2011-09-28 89 views
7

我在一個頁面上有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設置不會產生所希望的結果後。

有沒有其他明顯的方法我應該嘗試?

謝謝,
克里斯

回答

5

下面是一個使用佈局方式:

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

它調整自己的喜好。

+0

非常好。想想我所有的時間都在浪費轉換時間,那時候'grconvertX'就在那裏。有一天我必須坐下來閱讀基本功能列表。 – Aaron

6

嘗試使用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)