我有以下情节,我想在一个面板中显示所有这些图!我怎么能用矩阵呢?另外我想知道是否有其他方法而不是使用matrix和layout.
> 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)
Run Code Online (Sandbox Code Playgroud)
我希望在我的情节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
Run Code Online (Sandbox Code Playgroud)
但是,我的代码输出显示了不同的东西:
有人可以向我解释下面的图c(...)是如何构建的?

从 ?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.
Run Code Online (Sandbox Code Playgroud)
所以如果我们的矩阵是
matrix(1:4, 2, 2, byrow = TRUE)
## [,1] [,2]
## [1,] 1 2
## [2,] 3 4
Run Code Online (Sandbox Code Playgroud)
我们的布局是这样的

如果我们只想在顶行上绘制1个图,我们可以将矩阵指定为
matrix(c(1, 1, 2, 3), 2, 2, byrow = TRUE)
## [,1] [,2]
## [1,] 1 1
## [2,] 2 3
Run Code Online (Sandbox Code Playgroud)
并且布局将是

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
Run Code Online (Sandbox Code Playgroud)

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))
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
197 次 |
| 最近记录: |