分位数-分位数图:比较多个建模变量与一个守恒变量ggplot2 R [英] Quantile-Quantile plot: compare multiple modelled variables vs one oberved variable ggplot2 R

查看:43
本文介绍了分位数-分位数图:比较多个建模变量与一个守恒变量ggplot2 R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

样本数据

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 进行比较?

stat_qq and geom_qq seem be designed to compare one or more vectors e.g. sim1-6 vectors to a theoretical distribution. I couldn't see how to use it to compare multiple different vectors, e.g each of sim1 to sim6 compared against Observed?

但是,我有一个模型的输出( sim1-sim6 ),想检查建模后的输出是否与 Observed 进行比较.

However, I have the output of a model (sim1-sim6) and would like to check if the modelled output compares with the the Observed.

如何在 ggplot2 中完成此操作? y轴 sim1-sim6 x轴 Observed .

How can I accomplish this in ggplot2? The y-axis is sim1-sim6 and x-axis is 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 中完成相同的任务?

How can one possibly accomplish the same task in ggplot2?

推荐答案

您的意思是这样的吗?

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))

这篇关于分位数-分位数图:比较多个建模变量与一个守恒变量ggplot2 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆