我正试图绘制密度曲线图,只是为了表达想法。我尝试了以下代码:
这不是基于任何实际数据,我只需要一个漂亮的图像即可。
green1 <- rnorm(n=10000, mean=6, sd = .5)
green2 <- rnorm(n=10000, mean=18, sd = .5)
green3 <- rnorm(n=10000, mean=30, sd = .5)
green <- c(green1, green2, green3)
red1 <- rnorm(n=10000, mean=-2, sd = .01)
red2 <- rnorm(n=10000, mean=2, sd = .01)
red3 <- rnorm(n=10000, mean=10, sd = .01)
red4 <- rnorm(n=10000, mean=14, sd = .01)
red5 <- rnorm(n=10000, mean=22, sd = .01)
red6 <- rnorm(n=10000, mean=26, sd = .01)
red <- c(red1, red2, red3, red4, red5, red6)
plot(density(green), col= 'blue', xlim=c(-5,35))
lines(density(red), col= 'red')
但是,峰之间的红色曲线并不总是触及0线,并且将sd更改为较小值并不会有所不同。有人可以帮忙吗?
非常感谢!