围绕群体的边界

时间:2011-09-28 14:41:15

标签: r

我在一个页面上有16个绘图,以4x4网格排列。我想在每组2x2周围设置一个边框,但无法理解如何操作。

我最初使用layout(matrix(c(1,2,5,6,3,4,7,8,9,10,13,14,11,12,15,16), 4, 4, byrow=TRUE))来创建正确的布局,但据我所知,没有办法创建超出当前绘图和边距重叠的任何后续绘图的边距。

我尝试的第二种方法是使用split.screen(),认为任何oma()设置只适用于当前屏幕,但是,它似乎适用于整个窗口;例如,以下代码在整个显示区域的外部生成边框,而不是screen(1)

depths <- c(1:10)
split.screen(c(2,2))
screen(1)
par(oma=c(1,1,1,1))
plot(depths)
box("inner", lty="dotted", col="green")

设置box("inner")设置后,尝试使用box("outer")oma进行各种操作无法创建所需的结果。

我应该尝试其他明显的方法吗?

谢谢,
克里斯

2 个答案:

答案 0 :(得分:8)

尝试使用box("figure")

depths <- c(1:10)
split.screen(c(2,2))
screen(1)
box("figure")
split.screen(c(2,2))
par(cex=0.5)
screen(5)
plot(depths)

答案 1 :(得分:6)

以下是使用布局的方法:

layout(matrix(c(1,2,5,6,3,4,7,8,9,10,13,14,11,12,15,16), 4, 4, byrow=TRUE))
replicate(16, hist(rnorm(100)))
par(xpd=NA)
rect( grconvertX(0.005, from='ndc'), grconvertY(0.505, from='ndc'),
     grconvertX(0.495, from='ndc'), grconvertY(0.995, from='ndc'))
rect( grconvertX(0.005, from='ndc'), grconvertY(0.005, from='ndc'),
     grconvertX(0.495, from='ndc'), grconvertY(0.495, from='ndc'))
rect( grconvertX(0.505, from='ndc'), grconvertY(0.505, from='ndc'),
     grconvertX(0.995, from='ndc'), grconvertY(0.995, from='ndc'))
rect( grconvertX(0.505, from='ndc'), grconvertY(0.005, from='ndc'),
     grconvertX(0.995, from='ndc'), grconvertY(0.495, from='ndc'))

根据您的喜好进行调整。