stat_summary question

25 views
Skip to first unread message

Adam_L...@keybank.com

unread,
Sep 26, 2011, 11:54:42 AM9/26/11
to ggp...@googlegroups.com
I'm not sure what the issue here is. Am I missing something? The following does not generate a line connecting the means for each level of x, as I would expect (right or wrong). Any ideas? Thanks.

tst.data <- data.frame (x = c(rep("Blue",500), rep("Red",500)), y =c(rnorm(500,3,6), rnorm(500,8,4) ) )
ggplot ( data = tst.data,aes(x,y)) + geom_point(alpha = .3) + stat_summary(fun.y = "mean",geom = "line")




Adam Loveland




Email Classification: KeyCorp Internal
This communication may contain privileged and/or confidential information. It is intended solely for the use of the addressee. If you are not the intended recipient, you are strictly prohibited from disclosing, copying, distributing or using any of this information. If you received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. This communication may contain nonpublic personal information about consumers subject to the restrictions of the Gramm-Leach-Bliley Act. You may not directly or indirectly reuse or redisclose such information for any purpose other than to provide the services for which you are receiving the information. 127 Public Square, Cleveland, OH 44114


If you prefer not to receive future e-mail offers for products or services from Key
send an e-mail to mailto:DNERe...@key.com with 'No Promotional E-mails' in the SUBJECT line.

Adam_L...@keybank.com

unread,
Sep 26, 2011, 11:57:10 AM9/26/11
to ggp...@googlegroups.com
Nevermind! Figured it out. Thanks!


Adam Loveland

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example:
http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options:
http://groups.google.com/group/ggplot2

Kohske Takahashi

unread,
Sep 26, 2011, 11:57:33 AM9/26/11
to Adam_L...@keybank.com, ggp...@googlegroups.com
hi,

geom_line connects data points of the same group, so try this:

ggplot ( data = tst.data,aes(x,y, group=1)) + geom_point(alpha = .3) +


stat_summary(fun.y = "mean",geom = "line")


--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

Adam_L...@keybank.com

unread,
Sep 26, 2011, 12:26:12 PM9/26/11
to Kohske Takahashi, ggp...@googlegroups.com
Was having trouble labelling the mean that's calculated using stat_summary. Taking initial example (now with group added; thanks Kohske),

tst.data <- data.frame (x = c(rep("Blue",500), rep("Red",500)), y=c(rnorm(500,3,6), rnorm(500,8,4) ) )

ggplot ( data = tst.data,aes(x,y)) + geom_point(alpha = .3) +
stat_summary(aes(group=1),fun.y = "mean",geom = "line")

Above works.

tst.data <- data.frame (x = c(rep("Blue",500), rep("Red",500)), y=c(rnorm(500,3,6), rnorm(500,8,4) ) )

ggplot ( data = tst.data,aes(x,y)) + geom_point(alpha = .3) +

stat_summary(aes(group=1),fun.y = "mean",geom = "line") +
stat_summary(aes(group=1),fun.y = "mean",geom = "text")


This doesn't. It asks for the label, but I'm not sure how to add it (adding it as I would a usual aesthetic doesn't work). And of course, once I add it, I'd like to be able to format it somehow (e.g. dollar).

Thanks again.



Adam Loveland






From:        Kohske Takahashi <takahash...@gmail.com>
To:        Adam_L...@keybank.com
Cc:        ggp...@googlegroups.com
Date:        09/26/2011 12:01 PM
Subject:        Re: stat_summary question
Sent by:        ggp...@googlegroups.com




Hadley Wickham

unread,
Oct 4, 2011, 11:11:58 AM10/4/11
to Adam_L...@keybank.com, Kohske Takahashi, ggp...@googlegroups.com
I'd really recommend doing the summarise yourself - you'll have much
more flexibility.
Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages