【发布时间】:2013-11-30 10:57:02
【问题描述】:
我想画一个类似这张图的QQ图:
我设法使用两个样本获得了 QQ 图,但我不知道如何将第三个添加到图中。 这是我的结果:
这是我使用的代码:
qqplot(table$Bedouin, table$Tunisia, xlim = c(-0.25,0.25), ylim = c(-025,0.25))
在我的表格数据框中,我想添加其他人群。但我做不到。
提前谢谢你。
【问题讨论】:
我想画一个类似这张图的QQ图:
我设法使用两个样本获得了 QQ 图,但我不知道如何将第三个添加到图中。 这是我的结果:
这是我使用的代码:
qqplot(table$Bedouin, table$Tunisia, xlim = c(-0.25,0.25), ylim = c(-025,0.25))
在我的表格数据框中,我想添加其他人群。但我做不到。
提前谢谢你。
【问题讨论】:
你可以添加行
par(new=TRUE)
然后再次使用 qqplot() 对第一个图进行过度绘制,如下所示:
set.seed(10)
dat <- data.frame(A = rnorm(20), B = rnorm(20), C = rnorm(20))
# create a QQ-plot of B as a function of A
qqplot(dat$A, dat$B,
xlim = range(dat), ylim = range(dat),
xlab = "Distribution A", ylab = "Other distributions")
# set overplotting
par(new=TRUE)
# create a QQ-plot of B as a function of C
qqplot(dat$A, dat$C,
xlim = range(dat), ylim = range(dat),
xlab = "Distribution A",
ylab = "Other distributions",
col = "red")
# create a diagonal line
abline(a = 0, b = 1)
# create a legend
legend("bottomright", legend = c("B", "C"), pch = 1, col = c("black", "red"))
【讨论】:
我想您正在寻找排序值的散点图,因为所有变量都存储在同一个数据框中。
一个示例数据集:
set.seed(10)
dat <- data.frame(A = rnorm(20), B = rnorm(20), C = rnorm(20))
这是一种使用基本 R 函数创建绘图的方法:
# create a QQ-plot of B as a function of A
qqplot(dat$A, dat$B, xlim = range(dat), ylim = range(dat),
xlab = "A", ylab = "B/C")
# create a diagonal line
abline(a = 0, b = 1)
# add the points of C
points(sort(dat$A), sort(dat$C), col = "red")
# create a legend
legend("bottomright", legend = c("B", "C"), pch = 1, col = c("black", "red"))
【讨论】: