在 levelplot 中使用布局函数
Use layout function within levelplot
我在 R 中做映射,在 rasterVis
包中发现了非常有用的 levelplot
函数。我想在 window 中显示多个图。但是,par(mfcol)
不适合 lattice
。我发现 layout
函数对我来说非常有用,但它无法执行我想做的事情。
这是我的代码:
s <- stack(Precip_DJF1, Precip_DJF2, Precip_DJF3, Precip_DJF4,
Precip_DJF5, Precip_DJF6)
levelplot(s, layout(matrix(c(1, 2, 0, 3, 4, 5), 2, 3)),
at=seq(floor(3.81393), ceiling(23.06363), length.out=20),
par.settings=themes, par.strip.text=list(cex=0),
scales=list(alternating=FALSE))
使用
layout(matrix(c(1, 2, 0, 3, 4, 5), 2, 3))
失败,而 layout(3, 2)
有效,但绘图按行显示而不是按列显示。我希望图表显示在第 1 列,然后是第 2 列等。类似于:
mat <- matrix(c(1, 2, 3, 4, 5, 6), 2, 3)
> mat
# [,1] [,2] [,3]
# [1,] 1 3 5
# [2,] 2 4 6
levelplot
或lattice
中有做这种布局的功能吗?
提前致谢。
根据@Pascal 的建议,您可以使用 index.cond
来执行此操作:
例如:
library(rasterVis)
s <- stack(replicate(6, raster(matrix(runif(100), 10))))
levelplot(s, layout=c(3, 2), index.cond=list(c(1, 3, 5, 2, 4, 6)))
如果您不想对传递给 index.cond
的列表进行硬编码,您可以使用如下内容:
index.cond=list(c(matrix(1:nlayers(s), ncol=2, byrow=TRUE)))
其中 2
表示布局中的行数。
当然你也可以传递一个 stack
层按所需的行绘图顺序排列,例如:
levelplot(s[[c(matrix(1:nlayers(s), ncol=2, byrow=TRUE))]], layout=c(3, 2))
我在 R 中做映射,在 rasterVis
包中发现了非常有用的 levelplot
函数。我想在 window 中显示多个图。但是,par(mfcol)
不适合 lattice
。我发现 layout
函数对我来说非常有用,但它无法执行我想做的事情。
这是我的代码:
s <- stack(Precip_DJF1, Precip_DJF2, Precip_DJF3, Precip_DJF4,
Precip_DJF5, Precip_DJF6)
levelplot(s, layout(matrix(c(1, 2, 0, 3, 4, 5), 2, 3)),
at=seq(floor(3.81393), ceiling(23.06363), length.out=20),
par.settings=themes, par.strip.text=list(cex=0),
scales=list(alternating=FALSE))
使用
layout(matrix(c(1, 2, 0, 3, 4, 5), 2, 3))
失败,而 layout(3, 2)
有效,但绘图按行显示而不是按列显示。我希望图表显示在第 1 列,然后是第 2 列等。类似于:
mat <- matrix(c(1, 2, 3, 4, 5, 6), 2, 3)
> mat
# [,1] [,2] [,3]
# [1,] 1 3 5
# [2,] 2 4 6
levelplot
或lattice
中有做这种布局的功能吗?
提前致谢。
根据@Pascal 的建议,您可以使用 index.cond
来执行此操作:
例如:
library(rasterVis)
s <- stack(replicate(6, raster(matrix(runif(100), 10))))
levelplot(s, layout=c(3, 2), index.cond=list(c(1, 3, 5, 2, 4, 6)))
如果您不想对传递给 index.cond
的列表进行硬编码,您可以使用如下内容:
index.cond=list(c(matrix(1:nlayers(s), ncol=2, byrow=TRUE)))
其中 2
表示布局中的行数。
当然你也可以传递一个 stack
层按所需的行绘图顺序排列,例如:
levelplot(s[[c(matrix(1:nlayers(s), ncol=2, byrow=TRUE))]], layout=c(3, 2))