Say you have the following dataset:
trt <- ifelse(runif(100)<0.5,"drug","placebo") inj.site <- ifelse(runif(100)<0.5,"ankle","wrist") relief <- 20 + 0.5*(inj.site=="ankle") + 0.5*(trt=="drug") + rnorm(100) to.analyze <- data.frame(trt,inj.site,relief)
Now, the idea is to make a boxplot with injury site on the x-axis and boxes by treatment side-by-side:
bplot <- ggplot(to.analyze,aes(inj.site,relief,fill=trt)) + geom_boxplot(position="dodge")
Easy enough. But now I want to add raw data points on top of the boxes. If I didn't have boxes with position=dodge, this would be easy:
bplot + geom_point(aes(colour=trt))
However, this draws points in between the boxes, and adding a position="dodge" to this geometry does not seem to work. How do I adjust this so that points are drawn over the boxes?
Bonus: same situation with using stat_summary(blah,y.fun=mean,shape="+") to overplot the means, which has the same issue.