画图时如何在一组图形周围添加边框?

9
我有一个页面上有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")

在设置oma参数后,尝试使用box("inner")box("outer")进行各种尝试,但没有得到期望的结果。

是否还有其他明显的方法我应该尝试?

谢谢,
Chris

2个回答

9
尝试使用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)

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

根据您的偏好进行调整。


非常好。我竟然浪费了这么多时间来进行转换,而grconvertX一直在那里。总有一天,我一定要坐下来仔细阅读基本函数列表。 - Aaron left Stack Overflow

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接