Geoms in stat.summary

2,353 views
Skip to first unread message

Stefanie Trop

unread,
Mar 9, 2017, 11:19:43 AM3/9/17
to ggp...@googlegroups.com
Hello,

I want to use the stat.summary(fun.y = 'mean') command to add means to scatterplots of individual data points. I would like to use a horizontal line to indicate the mean. Can the geom = 'point' be specified to a shape other than a circle for the calculated mean? I want to use circles for the individual data points on my graph, so the default point as a circle for the mean does not look good.

Thanks!
Stefanie Trop

Brandon Hurr

unread,
Mar 9, 2017, 11:33:50 AM3/9/17
to Stefanie Trop, ggplot2
As far as I know there is no "line", but you can get the look you want by changing the point type to a cross (pch 3)

ggplot(mtcars, aes(cyl, mpg)) + geom_point() + stat_summary(fun.data = "mean_cl_boot", colour = "red", size = 2, shape = 3)

HTH,
B

--
--
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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Crump, Ron

unread,
Mar 9, 2017, 11:44:21 AM3/9/17
to Stefanie Trop, ggp...@googlegroups.com
Hi Stefanie,
I may not have understood your question, but how does this look:

data(diamonds)
ggplot(diamonds)+geom_point(aes(x=carat,y=price))+geom_hline(aes(yintercept
=mean(price)),colour="red")

Ron.

Stefanie Trop

unread,
Mar 9, 2017, 11:47:21 AM3/9/17
to Crump, Ron, ggp...@googlegroups.com
Thanks! Though, sorry, I wasn't clear. No, that's not what I want. The first response understood my question. I have a binary x, and want the mean y for x variable. I just want a different symbol than the circular point given by stat_summary(fun.y = 'mean', geom = 'point') gives.

Stefanie

Brandon Hurr

unread,
Mar 9, 2017, 12:30:52 PM3/9/17
to Stefanie Trop, Crump, Ron, ggp...@googlegroups.com
So, perhaps you're more after this?
ggplot(mtcars, aes(cyl, mpg)) + geom_point() + stat_summary(fun.y = "mean", colour = "red", size = 2, geom = "point", shape = 3)

Again, there is no "bar" point shape, but you could fudge it with geom_text...
ggplot(mtcars, aes(cyl, mpg)) + geom_point() + stat_summary(fun.y = "mean", colour = "red", size = 5, geom = "text", label= "-")

HTH.
B

Stefanie Trop

unread,
Mar 9, 2017, 12:40:56 PM3/9/17
to Brandon Hurr, Crump, Ron, ggp...@googlegroups.com
Ha, yes, simple is best! Text is perfect. Great idea, thanks!

Pedro Aphalo

unread,
Mar 10, 2017, 7:14:41 PM3/10/17
to ggplot2, brando...@gmail.com, R.E....@warwick.ac.uk
You can also use a single-character constant as argument to shape.
ggplot(mtcars, aes(cyl, mpg)) + geom_point() +

   stat_summary
(fun.y = "mean", colour = "red", size = 14, geom = "point", shape = "-")
and it gets positioned as expected for a symbol. Note that I increased size to 14.

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.
Reply all
Reply to author
Forward
0 new messages