I can build a density histogram, and I can build a regular histogram with custom bins, but not both. Here is my attempt:
library(ggplot2) vals = c(2.6, 5.2, 4.1, 6.9, 5.7, 5.2, 4.4, 5.5, 6.3, 6.1, 4.7, 1.4) myplot = qplot(vals, geom = 'blank') + geom_line(aes(y = ..density..), stat = 'density', colour = 26, size = 2, alpha = .6) + geom_histogram(aes(y = ..density..), binwidth = 1, fill = 28, alpha = 0.3) + stat_bin(breaks=seq(-.5,8.5,1)) + xlim(-1, 9) print(myplot)
If you delete the stat_bin member, the histogram will be correctly displayed as a density histogram, but with default cells. Add the stat_bin member and the boxes are correct, but this is no longer a density histogram. Any ideas how to make both work?
r ggplot2
user1956609
source share