Hello the community, I'm struggling with something I would wish was simple (but I might be just too novice to find out how to get what I want). I'm making use of geom_histogram with custom binwidth parameter. So fare, so good. But I'd wish to draw Poisson error bars which is computer by using the square root of the bin content: bincontent +/- sqrt(bincontent). And I'm not successful at it. How would you proceed without having to compute or extract yourself the bin contents ?
Here is some histogram without the desired error bars:
library(ggplot2)
dt <- data.frame(n = c(18, 19, 10, 24, 11, 15, 16, 15, 15, 14))
ggplot(dt, aes(x = n)) +
geom_histogram(binwidth = 5)
And here is an attempt which didn't work:
library(ggplot2)
dt <- data.frame(n = c(18, 19, 10, 24, 11, 15, 16, 15, 15, 14))
ggplot(dt, aes(x = n)) +
geom_histogram(binwidth = 5) +
geom_errorbar(aes(y = ..count.., ymin = ..count.. + sqrt(..count..), ymax = ..count.. - sqrt(..count..)), stat = 'count')
Thank you for your help