我有如下数据:
type1 <- c(rep(1,49), rep(2, 30), rep(3, 20), rep(4,1))
type2 <- c(rep(1,10), rep(2, 20), rep(3, 40), rep(4,20), rep(5,10))
type3 <- c(rep(5,49), rep(4, 30), rep(3, 20), rep(2,1))
dat2 <- data.frame(dens = c(type1, type2, type3), lines = rep(c("a", "b", "c"),
each = 100))
这是直方图:
require(ggplot2)
ggplot(dat2, aes(x = dens, fill = lines)) + geom_bar(position="dodge")+ theme_bw()
密度图并不完全适用,因为这是离散测量的:
ggplot(dat2, aes(x = dens, fill = lines)) + geom_density(alpha = 0.5)
除此之外,我想产生一个平滑的理论分布。我尝试了如下的 beta 发行版,我不确定如何才能最适合上面的数据(dat2)。
dat3 <- data.frame(dens = c(rbeta(4000000, 1, 3, ncp = 0),
rbeta(4000000, 2, 2, ncp = 0), rbeta(4000000, 3, 1, ncp = 0))
, lines = rep(c("a", "b", "c"), each = 4000000))
#Plot.
ggplot(dat3, aes(x = dens, fill = lines)) + geom_density(alpha = 0.5) + theme_bw()