Solved – How to add standard error to plots in ggplot2 with R

anovaggplot2r

I'm in the process of learning R, in the hope of replacing everything I do in SPSS/Sigmplot with R. It's going well so far 🙂 I've got to the point of running a repeated-measures ANOVA, but have come unstuck when trying to plot the results

I've worked out how to plot a set of means using ggplot2, but now I'm unsure of how to plot the standard error as error bars. I've seen a number of guides with different implementations, and none of them seem to be appropriate (or even agree with each other). Many people use standard deviations, which is not what I am after. Others have different methods of computing the standard error, so I'm unsure of the best way to proceed.

What I have so far is this:

qplot(CATEGORIES, means, shape=factor(ANOTHER_CATEGORY), facets=MORE_CATEGORIES ~ ., data=alldata)

I was wondering if someone could point me in the right direction in terms of how to get the standard errors from a repeated-measures ANOVA in R, and then how to translate this into error bars in ggplot?

Thanks!

Best Answer

The reason you're running into multiple methods is because the target variability to visualize in a repeated measures design is not necessarily that straightforward to determine.

If you calculate the conventional SE then what you've done is give an estimate of how well you calculated the raw score. However, generally in a repeated measures design that wasn't the goal of the study. What you are typically looking to do is to calculate an effect. The variability of that effect is much less. I generally recommend plotting your effects only and the variability of your effect estimates (better as confidence intervals than SEs). Then the error bar will represent something about what you actually attempted to study. The effect SE will be the sqrt(MSe/n) where n is the number of measurements of the effect (not to be confused with number of S's).