ggplot Poisson density curve: why zigzag lines?

2019-07-07 01:43发布

问题:

I would like to plot the density function of a Poisson distribution. I am not sure why I get a jaggy line (in blue). On the sample plot, the normal density curve (in red) looks smooth. It is because the reason the Poisson density function doesn't accept decimal values? How to eliminate the zigzag in the Poisson density plot? Thanks very much for any help.

library(ggplot2)
ggplot(data.frame(X = seq(5, 30)), aes(x = X)) +
  stat_function(fun=dpois, geom="line", size=2, color="blue3", args =  list(lambda = 15)) +
  stat_function(fun=dnorm, geom="line", size=2, color="red4", args = list(mean=20, sd=2))