【发布时间】:2014-07-09 20:01:19
【问题描述】:
我在 R 中使用 layout() 来生成一系列 9 个图形(在 3x3 布局中)
m <- rbind(c(1,2,3), c(4,5,6), c(7,8,9))
layout(m)
我试图在三列之间放置 2 条垂直线,以便将各列彼此分开。 box() 不合适,因为我希望将行链接起来,因此不希望有行,我正在努力寻找使用 line() 函数的任何帮助,任何想法都将不胜感激。
谢谢
【问题讨论】:
我在 R 中使用 layout() 来生成一系列 9 个图形(在 3x3 布局中)
m <- rbind(c(1,2,3), c(4,5,6), c(7,8,9))
layout(m)
我试图在三列之间放置 2 条垂直线,以便将各列彼此分开。 box() 不合适,因为我希望将行链接起来,因此不希望有行,我正在努力寻找使用 line() 函数的任何帮助,任何想法都将不胜感激。
谢谢
【问题讨论】:
如果您更改图形参数以将所有绘图剪切到设备区域,然后使用abline() 添加垂直线以进行分隔怎么办?例如:
m <- rbind(c(1,2,3), c(4,5,6), c(7,8,9))
# Clips drawing to the device region
# See ?par for more details of the argument
par(xpd=NA)
layout(m)
# Insert you nine plots here
for(i in 1:9) {
plot(1,1)
}
# Check the correct coordinates with
# locator(), and the arguments
# accordingly. These are about right,
# if the plot region is rectangular.
abline(v=0.25)
abline(v=-1.06)
结果图应如下所示。
【讨论】:
另一种选择是与layout一起玩:
layout(rbind(c(1,10, 2,11,3),
c(4,10, 5,11,6),
c(7,10, 8,11,9)),
widths=c(1, lcm(3), 1,lcm(3),1),
respect=TRUE)
## you plot your 9 plots
for(i in 1:9) {
plot(1,1)
}
## you plot the separation
plot(1,1,type='n',axes=FALSE, ann=FALSE)
## here I use a vertical line but you can plot anything (box, segments,..)
abline(v=1)
plot(1,1,type='n',axes=FALSE, ann=FALSE)
abline(v=1)
【讨论】:
grconvertX 是@JTT 建议locator 查找行位置的替代方案:
m <- rbind(c(1,2,3), c(4,5,6), c(7,8,9))
layout(m)
for(i in 1:9) {
plot(1,1)
}
abline(v=grconvertX(1:2/3, 'ndc', 'user'))
【讨论】: