R中的嵌套图

R中的嵌套图,r,R,早上好 我试图创建1 x 3的绘图,其中每个单独的绘图本身是3 x 3的组合绘图。下面的数字表示单个绘图ID 1 2 3 <space> 10 11 12 <space> 19 20 21 4 5 6 <space> 13 14 15 <space> 22 23 24 7 8 9 <space> 16 17 18 <space> 25 26 27 R脚本 library(car) sampledata <- read

早上好

我试图创建1 x 3的绘图,其中每个单独的绘图本身是3 x 3的组合绘图。下面的数字表示单个绘图ID

1 2 3 <space> 10 11 12 <space> 19 20 21
4 5 6 <space> 13 14 15 <space> 22 23 24
7 8 9 <space> 16 17 18 <space> 25 26 27
R脚本

library(car)
sampledata <- read.table("H:/sample.txt", header=TRUE)
y.1 <- sampledata$Y1
y.2 <- log(sampledata$Y2)
y.3 <- sqrt(sampledata$Y3)
x.1 <- sampledata$X
x.2 <- (sampledata$X)^2

par(mfrow=c(1,3))

par(mfrow=c(3,3))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1 + x.2), layout = NA)
title("Plot 1 - Plot 9", outer=TRUE, line =-2)

par(mfrow=c(3,3))
leveragePlots(lm(y.2 ~ x.1))
leveragePlots(lm(y.2 ~ x.1))
leveragePlots(lm(y.2 ~ x.1))
leveragePlots(lm(y.2 ~ x.1))
leveragePlots(lm(y.2 ~ x.1))
leveragePlots(lm(y.2 ~ x.1))
leveragePlots(lm(y.2 ~ x.1))
leveragePlots(lm(y.2 ~ x.1 + x.2), layout = NA)
title("Plot 10 - Plot 18", outer=TRUE, line =-2)

par(mfrow=c(3,3))
leveragePlots(lm(y.3 ~ x.1))
leveragePlots(lm(y.3 ~ x.1))
leveragePlots(lm(y.3 ~ x.1))
leveragePlots(lm(y.3 ~ x.1))
leveragePlots(lm(y.3 ~ x.1))
leveragePlots(lm(y.3 ~ x.1))
leveragePlots(lm(y.3 ~ x.1))
leveragePlots(lm(y.3 ~ x.1 + x.2), layout = NA)
title("Plot 19 - Plot 27", outer=TRUE, line =-2)
库(车)
sampledata提供了一个关于如何使用multiplot(p1、p2、p3、p4、cols=2)命令排列多个绘图的好例子

注意:我不熟悉leveragePlots命令,它显然包含在汽车库中

就你而言: 然后,可以使用如下方式“构建”每个单独的图p1、p2和p3:

require(ggplot2)

# first subplot
p1 = ggplot(data, aes(x = x, y = y1))
p1 = p1 + geom_point()
p1 = p1 + facet_grid(y2 ~ y3)
p1

# second subplot
p2 = ggplot(data, aes(x = x, y = y2))
p2 = p2 + geom_point()
p2 = p2 + facet_grid(y1 ~ y3)
p2

# third subplot
p3 = ggplot(data, aes(x = x, y = y3))
p3 = p3 + geom_point()
p3 = p3 + facet_grid(y1 ~ y2)
p3
最后用multiplot命令安排。(您需要使用我链接到的页面底部的代码使multiplot命令可用)


您是否考虑过分别使用这些软件包中的
ggplot2
restrape2
、函数
facet\u grid()
melt()
?我目前正在分析它,很快就会恢复。如果您真的想要页面上的27个绘图,为什么不使用
par(mfrow=c(3,9))
?另一种选择是
网格。在gridExtra包中排列
命令感谢您的评论。我试着在一个多点中做一个多点。我会尝试尝试你提出的建议,并尽快回复。只是一个简单的例子,可以使用par(mfrow=c(3,3))在multiplot中创建multiplot,即嵌套的multiplot吗multiplot@SaravananK:显示布局()和par()。我不确定它们是否可以组合使用(即,外部图形使用layout,内部图形使用par())以实现所需的结果。但如果是这样的话,这将是一个舒适的解决方案,并且只依赖于基本图形。
require(ggplot2)

# first subplot
p1 = ggplot(data, aes(x = x, y = y1))
p1 = p1 + geom_point()
p1 = p1 + facet_grid(y2 ~ y3)
p1

# second subplot
p2 = ggplot(data, aes(x = x, y = y2))
p2 = p2 + geom_point()
p2 = p2 + facet_grid(y1 ~ y3)
p2

# third subplot
p3 = ggplot(data, aes(x = x, y = y3))
p3 = p3 + geom_point()
p3 = p3 + facet_grid(y1 ~ y2)
p3
multiplot(p1,p2,p3, cols = 3)