Histogram of mean per bin

14 views
Skip to first unread message

Doug Mitarotonda

unread,
Nov 15, 2012, 3:20:16 PM11/15/12
to ggp...@googlegroups.com
Hi,
I am trying to create a histogram where the bin heights are the mean of the values that fall into each bin. The code for p2 below is what I thought would work.

library(ggplot2)
m <- mtcars[1:20, ];
p <- ggplot(m, aes(x = mpg)) + geom_histogram(binwidth = 5);
p <- p + aes(weight = wt); # works, but is the sum of the wt
p2 <- p + aes(weight = wt / ..count..); # does not work, but the idea I am going for

Sorry if I am missing something obvious here, but I appreciate the help.

Doug
Reply all
Reply to author
Forward
0 new messages