样本数据
set.seed(10)
dat <- data.frame(Observed = rnorm(20),
sim1= rnorm(20), sim2 = rnorm(20),
sim3 = rnorm(20),sim4 = rnorm(20),
sim5 = rnorm(20),sim6 = rnorm(20)
)
stat_qq
和geom_qq
似乎旨在比较一个或多个向量,例如sim1-6向量达到理论分布。我看不到如何使用它来比较多个不同的向量,例如将sim1
到sim6
与Observed
进行比较?
但是,我有一个模型(sim1-sim6
)的输出,并想检查建模输出是否与Observed
进行比较。
如何在ggplot2
中完成此操作? y-axis
是sim1-sim6
,而x-axis
是Observed
。
记住:我正在比较sim
和Observed
中的每一个。
欢迎提出所有建议。
编辑:BASE R中的解决方案
set.seed(10)
dat1 <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
#
# create a QQ-plot of Sims as a function of Observed
qqplot(dat1$Observed, dat$sim1, xlim = range(dat1), ylim = range(dat1),
xlab = "Observed", ylab = "Sims....")
# create a diagonal line
abline(a = 0, b = 1)
# add the points of sims
points(sort(dat1$Observed), sort(dat1$sim2), col = "red")
points(sort(dat1$Observed), sort(dat1$sim3), col = "blue")
points(sort(dat1$Observed), sort(dat1$sim4), col = "green")
points(sort(dat1$Observed), sort(dat1$sim5), col = "magenta")
points(sort(dat1$Observed), sort(dat1$sim6), col = "purple")
我的问题:
如何在ggplot2
中完成同一任务?
答案 0 :(得分:2)
你的意思是这样吗?
library(ggplot2)
library(reshape2)
data = melt(dat, id.vars = "Observed")
ggplot(data) +geom_qq(aes(sample=value)) +
geom_qq_line(aes(sample=Observed)) +
facet_wrap(~variable)
更新
data = melt(dat, id.vars = "Observed")
ggplot(data) +geom_qq(aes(sample=value, color = variable)) +
geom_qq_line(aes(sample=Observed))