stat_summary and size

已查看 19 次
跳至第一个未读帖子

David Bess

未读,
2014年4月22日 14:27:082014/4/22
收件人 ggp...@googlegroups.com

Greetings,

 

I am trying to create a graph where the y axis is some numeric data, the y axis is a factor group, and points represent the mean of the numeric data for each factor group. Further I need the size of the points to be scaled by the proportional number of observations in each group. This last part is where I keep getting stuck, even after hours of google searching and re-reading ggplot2 in its entirety.

 

Here is the code I have working...it uses the mtcars dataset which I think most people have available.


fig1 <- ggplot(mtcars, aes(cyl, mpg))

fig1 + stat_summary(fun.y = mean, geom = "point", size = 5,
aes(group = 1), color = "red")

 

The only thing that is missing is that I need the size to be scaled based on the proportional number of observations in each group.

 

Thanks in advance,

 

David

Ben Bond-Lamberty

未读,
2014年4月22日 14:44:482014/4/22
收件人 David Bess、ggplot2
I'd probably pre-summarize the data, e.g. using the plyr package:

mtcars1 <- ddply(mtcars,.(cyl),summarise,mpg=mean(mpg),n=length(cyl))

...and then plot using mtcars1.

Ben
> --
> --
> 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/d/optout.
回复全部
回复作者
转发
0 个新帖子