A simple way is to overlay densities instead of counts and use stat_function ()
library(ggplot2) value<-c(rpois(500,1.5)) group<-rep(c("A","B"),250) data<-data.frame(value,group) ggplot(data,aes(value)) + geom_histogram(aes(y=..density..), binwidth=1,position="identity") + facet_grid(.~group) + stat_function(geom = "line", fun = dpois, arg = list(lambda = 1.5), colour = "red", fill = NA, n = 9)
If you want to count, then you need to convert dpois densities to "counts"
ggplot(data,aes(value)) + geom_histogram(aes(y=..count..), binwidth=1,position="identity") + facet_grid(.~group) + stat_function(geom = "line", fun = function(..., total){dpois(...) * total}, arg = list(lambda = 1.5, total = 250), colour = "red", fill = NA, n = 9)
source share