2015-05-10 20 views
3

我想繪製三個圖表在一起,一個在另一個之下。 我想使第一個圖表的高度與使用par的其他圖表的高度相差兩倍,但我對高度參數有困難。R:設置多個標繪高度與參數

par(mfrow = c(3, 1),mar=c(2, 4, 2, 0.2), heights=c(2,1,1)) 

plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l") 
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l") 
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l") 

謝謝你的幫忙。

回答

3

您可以使用layout此:

#the first argument is a matrix that shows the order of the graphs 
#in this case the matrix has 1 column and 3 rows. therefore, graphs 1,2,3 
#will be ploted in this order, one below the other 
#you then need to adjust the heights and the widths for each plot 
nf <- layout(matrix(c(1,2,3),ncol=1), widths=c(4,4,4), heights=c(2,1,1), TRUE) 
#typing the below command will let you see how the plots will be filled in. 
#layout.show(nf) 

#then you just run your plots 
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l") 
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l") 
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l") 

enter image description here