R ggplot2: Points, lines and error bars in plot overlap inconsistently

I need to plot some things, my data is available in a previous post, which helped me quite a lot in dealing with ggplot2. (In that previous post, I needed the following plot binned by quantiles of variable miht.binned, but as it comes to formal layout, I start with a more simple plot without that binning variable.)

My current best plot version is:

I am almost satisfied, except that the points, lines and bars seem to overlap inconsistently. Especially, when you look at the negative group at T1, it is overridden by the black line which doesn't look very professional. Is there a way, to work around this and make overlaps being in a more consistent, meaningful way? The issue is independent of export format (image, pdf).

The code for this plot:

pd <- position_dodge(.2)
ggplot(MyData, aes(x=time, y=ias, colour=GROUP, group=GROUP, 
                                 shape=GROUP)) + 
  stat_summary(fun.data = "mean_se", geom="errorbar",position=pd) +
  stat_summary(fun.y="mean", geom="point", size=8,position=pd) + 
  stat_summary(fun.y="mean", geom="line",position=pd) + 
  scale_x_discrete(breaks=c("0", "1", "2"), labels=c("T0", "T1", "T2"))+
  coord_cartesian(ylim=c(2, 7)) + 
  scale_y_continuous(breaks=seq(2, 6, 2)) +
  scale_color_manual(values=c("gray30", "gray50","gray70"),name  ="Gruppe",
                                           breaks=c("baseline", "negative", "neutral"),
                                            labels=c("Baseline", "Attend-negative", "Attend-neutral")) +
  scale_shape_discrete(name  ="Gruppe",
                       breaks=c("baseline", "negative", "neutral"),
                       labels=c("Baseline", "Attend-negative", "Attend-neutral")) +
  theme(
    panel.grid.major.y = element_line(colour = "gray80", size = NULL, linetype = NULL,  # horizontale Linien
                                      lineend = NULL)
    ,panel.grid.minor.y = element_line(colour = "gray90", size = NULL, linetype = NULL,
                                       lineend = NULL)
    ,panel.grid.major.x = element_blank()           # vertikale Linien
    ,panel.grid.minor.x = element_blank()
    ,legend.background = element_rect(fill = "white", colour = "white") # Legende 
    ,legend.key = element_rect(fill = "white", colour = "white")
    ,panel.background = element_rect(fill = "white", colour = "white", size = NULL, # Panel Hintergrund
                                     linetype = NULL)
    ,axis.line = element_line(colour = "black", size=.5)
    ,axis.ticks.x = element_line(colour = "black", size=.5)
    ,axis.ticks.y = element_line(colour = "black", size=.5)
    ,axis.ticks.length =  unit(0.5, "cm")
    ,axis.ticks.margin =  unit(.3, "cm")
    ,axis.title.x = element_text(family = NULL, face = "bold", size = 11,vjust=0.1)
    ,axis.title.y = element_text(family = NULL, face = "bold", size = 11,vjust=0.1)
    ,axis.text=element_text(colour="black")
    ,legend.title = element_text(family = NULL, face = "plain", size = 11)
    ,legend.text = element_text(family = NULL, face = "plain", size = 9)
  ) +
  xlab("Messzeitpunkt")+
  ylab("State-KA (M)") 

Answers


Just change the order of stat_summary() calls in the order you need (they plotted in actual plot in the order they are called in your code) - first errorbars, then lines and points as last.

  + stat_summary(fun.data = "mean_se", geom="errorbar",position=pd) +
  stat_summary(fun.y="mean", geom="line",position=pd) + 
  stat_summary(fun.y="mean", geom="point", size=8,position=pd) 

Need Your Help

jquery selector not finding elements when it loaded by ajax

javascript jquery html ajax

When I load &lt;select id="myid" &gt; Element by ajax from my server . this selector not Working . But when I put this code in html and not Load by Ajax this selector is working good...

Repeating items in the list

c# list repeat items

Items that has the same item numbers should not repeat in the list, I tried this piece of code but it's not helping.