2015-02-09 21 views
3

我有8個地塊,我想繪製所有的一頁。每個圖是使用基本圖形制作的,我寧願堅持使用,而不是使用latticeggplot如何調整佈局在R的行的寬度

下面的方案是一個頁面,其中每個數字表示哪個繪圖#佔據該頁面的比例。有沒有辦法與layout或任何其他基本功能做到這一點?

1111122 
3333444 
5556666 
7788888 

一些代碼,我到目前爲止有:

pdf("test.pdf",height=30,width=10) 
widths = c(5/7,2/7,4/7,3/7,3/7,4/7,2/7 5/7) # this doesn't work 

x=layout(matrix(1:8,nrow=4,ncol=2,byrow=T), widths=widths, 
     heights=rep(1/4,4)) 

for (ix in 1:4){   

    plot(rnorm(100)) 
    plot(rnorm(100)) 
} 
dev.off() 

回答

3

您可以指定佈局的矩陣,並使用layout功能。

mat <- t(sapply(1:4, function(x) 
         rep.int(c((x - 1) * 2 + 1, (x - 1) * 2 + 2), c(6 - x, 1 + x)))) 
#  [,1] [,2] [,3] [,4] [,5] [,6] [,7] 
# [1,] 1 1 1 1 1 2 2 
# [2,] 3 3 3 3 4 4 4 
# [3,] 5 5 5 6 6 6 6 
# [4,] 7 7 8 8 8 8 8 

layout(mat) 

for (i in 1:8) { 
    plot(rnorm(10)) 
} 

如果在佈局矩陣中重複相同的數字,該圖將使用與該數字對應的空間。

enter image description here