Three normal distributions plotted by R language with ggplot2 package |
以下是程式碼:
rm(list = ls())
library(ggplot2)
dat <- data.frame(
abscissa <- seq(-10,10,length=1000),
norm1 <- dnorm(abscissa,mean=0,sd=1),
norm2 <- dnorm(abscissa,mean=3,sd=1),
norm3 <- dnorm(abscissa,mean=-3,sd=1)
)
p <- ggplot(data=dat, aes(x=abscissa)) +
geom_area(aes(y=norm1), color="black", fill="green4", alpha=0.6) +
geom_area(aes(y=norm2), color="black", fill="blue", alpha=0.6) +
geom_area(aes(y=norm3), color="black", fill="red", alpha=0.6) +
coord_cartesian(xlim = c(-6, 6)) +
xlab("z") + ylab("density") +
ggtitle("Normal Distributions")
print(p)
更多關於上述繪圖套件請參考《R的ggplot2基本概念》
_EOF_
沒有留言:
張貼留言