2
votes
$\begingroup$

First of all, my data:

http://www.pastebin.ca/2599202 (I hope this is not too inconvenient, because I fail creating good fitting example data)

What I basically need, is a plot like: enter image description here

I plotted the repeated measures factor time(x-axis, 3 levels) against ias (continuous dependent variable) for my 3 experimental groups. I did this 4 times (for each quantile of my trait-measure MIHT, miht.binned, .25 - 1.00).

I have to admit I am not really an R professional and the ggplot2 manual simply is an overkill for me. I created the plot with ezPlot (from ezANOVA) and only managed to do a bit layout tweaking with ggplot2:

   PlotIAS = ezPlot(                               
      data = MyData
      , dv = .(ias)
      , wid = .(id)
      , between = .(GROUP, miht.binned)
      , within = .(time)
      , x = .(time)
      , split = .(GROUP)
      , col   = .(miht.binned)
      , x_lab = 'time of measurement'
      , y_lab = 'IAS Score (Mean)'
      #, do_bars = FALSE
      , type = 3
    )


    PlotIAS = PlotIAS +  
      theme(
        panel.grid.major.y = element_line(colour = "gray80", size = NULL, linetype = NULL,  
                                          lineend = NULL)
        ,panel.grid.minor.y = element_line(colour = "gray90", size = NULL, linetype = NULL,
                                           lineend = NULL)
        ,panel.grid.major.x = element_blank()           
        ,panel.grid.minor.x = element_blank()
        ,legend.background = element_rect(fill = NULL, colour = "black") 

        ,panel.background = element_rect(fill = "white", colour = "white", size = NULL, 
                                         linetype = NULL)
      )

print(PlotIAS)

I did'nt find any information about these error bars ezPlot creates. They seem to be all the same. I just need to have error bars with SE or CI. I don't know if it is possible to add these in my ezPlot-based code (and how?) or if one has to create a complete new ggplot object for that (which is an overcharge for me...). Help is highly appreciated.

$\endgroup$
2

2 Answers 2

1
vote
$\begingroup$

I am not sure if changing the error bars in ezPlot is possible, but this ggplot code basically reproduces your plot with SE for the error bars.

pd <- position_dodge(.2)
ggplot(MyData,aes(x=time,y=ias,color=GROUP,group=GROUP)) + 
  geom_line(stat="summary",stat_params=list(fun.y="mean"),position=pd) + 
  geom_point(stat="summary",stat_params=list(fun.y="mean"),position=pd) + 
  stat_summary(fun.data = "mean_se", geom="errorbar",position=pd) +
  facet_grid(. ~ miht.binned)
$\endgroup$
2
  • $\begingroup$ Thank you. "ymax not defined: adjusting position using y instead" is some kind of error/warning, but doesn't seem to affect the production of the plot, right? $\endgroup$
    – entne
    Jan 30, 2014 at 9:11
  • $\begingroup$ I think that is right. $\endgroup$
    – tomr
    Jan 30, 2014 at 14:35
1
vote
$\begingroup$
pd <- position_dodge(.2)
ggplot(MyData,aes(x=time,y=ias,color=GROUP,group=GROUP)) + 
  geom_line(stat="summary",stat_params=list(fun.y="mean"),position=pd) + 
  geom_point(stat="summary",stat_params=list(fun.y="mean"),position=pd) + 
  stat_summary(fun.data = "mean_se", geom="errorbar",position=pd) +
  facet_grid(. ~ miht.binned)

For this example, how can I change the error bars to standard error shaded areas instead of lines? thank you,

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.