泊松分布的ggplot直方图

时间:2017-11-10 08:26:44

标签: r ggplot2 histogram poisson

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

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

非常感谢你。

1 个答案:

答案 0 :(得分:2)

这是代码。 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")

enter image description here

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

相关问题