使用R中的layout()划分图形的线条

时间:2014-05-21 09:09:23

标签: r layout plot line margin

我在R中使用layout()来生成一系列9个图形(以3x3布局)

    m <- rbind(c(1,2,3), c(4,5,6), c(7,8,9))
    layout(m)

我正在尝试在三列之间放置两条垂直线,以便将列彼此分开。 box()不合适,因为我想要链接行,所以不想在那里使用行,我很难找到任何使用line()函数的帮助,任何想法都会受到赞赏。

由于

3 个答案:

答案 0 :(得分:1)

如果更改图形参数以便将所有绘图剪切到设备区域,然后使用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)

结果图如下所示。

enter image description here

答案 1 :(得分:1)

另一种选择是使用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)

enter image description here

答案 2 :(得分:0)

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

enter image description here