Mean Dashed Line Boxplot

53 views
Skip to first unread message

J H

unread,
Mar 4, 2014, 8:54:56 AM3/4/14
to ggp...@googlegroups.com
I would like to overlay a mean dashed line for geom_boxlot(). Default seems median. Do I need to calculate the mean separately and then use line code to overlay?  Also how do I show the actual value of the mean? 

I am new to ggplot2 even though much much easier than learning base R I am still trying to figure it out. If there is an example you could share that would be great. Thanks in advance. 

Roman Luštrik

unread,
Mar 4, 2014, 10:14:14 AM3/4/14
to J H, ggplot2
I prefer to pre-calculate everything and add that to the plot. You are probably looking for geom_vline or geom_hline (http://docs.ggplot2.org/current/geom_vline.html).

Cheers,
Roman


On Tue, Mar 4, 2014 at 2:54 PM, J H <renalcl...@gmail.com> wrote:
I would like to overlay a mean dashed line for geom_boxlot(). Default seems median. Do I need to calculate the mean separately and then use line code to overlay?  Also how do I show the actual value of the mean? 

I am new to ggplot2 even though much much easier than learning base R I am still trying to figure it out. If there is an example you could share that would be great. Thanks in advance. 

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
In God we trust, all others bring data.

Suo Liu

unread,
Mar 12, 2014, 3:40:37 PM3/12/14
to ggp...@googlegroups.com
data(iris)
p <- ggplot(iris, aes(x=as.numeric(Species), y=Sepal.Length)) + 
  geom_boxplot(aes(x=Species)) + 
  stat_summary(geom='line', fun.y="mean", color='red', linetype=2)
p

This is a reproducible example, I think this is what you want.
Reply all
Reply to author
Forward
0 new messages