泊松分布的ggplot直方图

ggplot histogram of Poisson distribution

如何制作 lambda = 2.5 的泊松分布的 ggplot 直方图? x 轴 = 0:10。

在这个直方图中,我需要用颜色表示P(X>=4),x=0:4一种颜色,x=5:10另一种颜色。

非常感谢。

这是它的代码。 R 包含一个根据最常见的分布生成数据的函数。您只需要根据您的标准进行分类即可。

# Generate data
d <- rpois(n = 10e5, lambda = 2.5)

# categorise the data according to your criteria
data <- data.frame(d = d, 
                   col = ifelse(d < 5, "red", "blue"))

library(ggplot2)

ggplot(data, aes(x = d, fill = col)) +
  geom_histogram(bins = 14, color = "black")

但是,建议在发布问题之前做更多的研究。