I have a grouped boxplot with ggplot2 like this
p <- qplot(factor(cyl), mpg, data=mtcars, geom="boxplot", fill=factor(gear))
and I want to overdraw the mean points. I've tried this
p+ stat_summary(fun.y=mean, colour="red", geom="point")
but, I don't get the mean points over the boxes of each group.
What should I do to get this?
You should set position to position_dodge()
and width
to 0.75 - so points will be placed in the same way as boxplots.
qplot(factor(cyl), mpg, data=mtcars, geom="boxplot", fill=factor(gear)) +
stat_summary(fun.y=mean, colour="red",
geom="point",position=position_dodge(width=0.75))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With