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.
You could just calculate the means with something like this: