2014-02-12 55 views
1

我有以下情節,我想在一個面板中顯示它們全部!我如何使用矩陣來做到這一點?另外我想知道是否有其他方法,而不是使用matrixlayout如何在R中的一個面板中顯示多個圖?

> plot(density(Boston$tax)) 
> rug(Boston$tax, col=2, lwd=3.5) 
> hist(Boston$tax) 
> rug(Boston$tax, col=2, lwd=3.5) 
> table(Boston$chas) 
Off On 
471 35 
> barplot(table(Boston$chas)) 

> f1<-layout(matrix(c(0, 1,1,1,0,2,2,2,0,3,3,3) ,nrow = 4, ncol = 4, byrow = TRUE)) 
> layout.show(f1) 

我想有這樣的結構,爲我區1,2和3:

##  [,1] [,2] [,3] [,4] 
## [1,] 0 1 1 1 
## [2,] 0 2 2 2 
## [3,] 0 3 3 3 
## [4,] blank0 0 0 

但是我的代碼的輸出顯示不同的東西: enter image description here 有人能向我解釋如何下圖c(...)已經構建完成了嗎? enter image description here

+0

我知道有這樣的:'佈局(矩陣(c(1,1,2,2,3,4),nrow = 4,ncol = 4,byrow = TRUE))'我不知道如何把我的在右上方3 * 3角落裏有三塊地塊!就像我不確定'c(1,2,2,3,4)'。任何提示? –

+1

我編輯了我的答案,以顯示矩陣如何控制佈局。嘗試編制不同的矩陣,將它們設置爲佈局,然後查看'layout.show'來查看繪圖設備是如何分割的 –

回答

5

?layout

Description: 

    ‘layout’ divides the device up into as many rows and columns as 
    there are in matrix ‘mat’, with the column-widths and the 
    row-heights specified in the respective arguments. 

所以,如果我們的矩陣是

matrix(1:4, 2, 2, byrow = TRUE) 
##  [,1] [,2] 
## [1,] 1 2 
## [2,] 3 4 

我們的佈局是像這樣

enter image description here

如果我們只希望在1個情節最上面一行,我們可以指定我們的矩陣

matrix(c(1, 1, 2, 3), 2, 2, byrow = TRUE) 
##  [,1] [,2] 
## [1,] 1 1 
## [2,] 2 3 

和佈局將

enter image description here

mat <- matrix(1:3, 3, 3) 
mat <- rbind(cbind(0, mat), 0) 
##  [,1] [,2] [,3] [,4] 
## [1,] 0 1 1 1 
## [2,] 0 2 2 2 
## [3,] 0 3 3 3 
## [4,] 0 0 0 0 

enter image description here

layout(mat) 

plot(density(Boston$tax)) 
rug(Boston$tax, col=2, lwd=3.5) 
hist(Boston$tax) 
rug(Boston$tax, col=2, lwd=3.5) 
barplot(table(Boston$chas)) 

enter image description here

+0

您可以看看更新後的問題嗎?感謝您的好解釋。 –

+2

@MonaJalal我想我最後的編輯就是你要找的東西 –

相關問題