多个(rasterVis)水平图 [英] multiple (rasterVis) levelplots

查看:254
本文介绍了多个(rasterVis)水平图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常想在一个图上调整一个栅格堆栈的两个水平图.似乎rasterVis::levelplot并没有采用par(mfrow = c(...))选项来拆分窗格.一个示例,该示例使用两个栅格堆栈,这些栅格堆栈应在新的绘图窗口上并排排列:

i'm quite desperate trying to adjust two levelplots of one rasterstack each on one plot. It seems like rasterVis::levelplot does not take the par(mfrow = c(...)) option for splitting the pane. An example using two rasterstacks that shall be arranged side by side on a new plot window :

f <- system.file("external/test.grd", package="raster")
r1 <- stack(raster(f),log(raster(f)))
r2 <- stack(raster(f)-500,raster(f)+500)

par(mfrow=c(2,2))
  levelplot(r1)
  levelplot(r2)

在这里,levelplot(r1)在全比例窗口上绘制,而levelplot(r2)不幸的是在levelplot(r1)上绘制.

Here, levelplot(r1) is being plotted on the full scale window, while levelplot(r2) unfortunately is painting over levelplot(r1).

我试着玩,用print函数包装对levelplot的调用,该函数需要splitnewpage = false选项.不幸的是,我对如何正确使用split没有任何了解,因此我最终只有沮丧.

I tried to play around, wrapping the call for levelplot with the print function, which takes split as well as newpage = false options. Unfortunately I do not get the twist on how to use split properly so I end up with nothing but frustration.

非常感谢您的帮助,在此先感谢

I'd really appreciate your help, thanks in advance

安迪

推荐答案

对于基于网格的图形,包括由 lattice ( rasterVis 的绘图功能), gridExtra 功能grid.arrange()par(mfcol=)对于基本R图形所做的+/-相同.

For grid-based graphics, including those produced by lattice (which underlies rasterVis' plotting functions) the gridExtra function grid.arrange() does +/- the same thing as par(mfcol=) does for base R graphics.

library(gridExtra)
p1 <- levelplot(r1)
p2 <- levelplot(r2)
grid.arrange(p1, p2, ncol=2)

另一种特定于 lattice 的解决方案使用print.trellis()自变量print.trellis(),这是格子图的绘制方法(ht baptiste& OscarPerpiñán) . split=接受四个数字的向量.向量的第3和第4个元素给出了显示中的列数和行数,而其第1和第2个元素给出了要打印的对象的列和行位置.

An alternative lattice-specific solution uses the split= argument to print.trellis(), the plotting method for lattice plots (h.t. baptiste & Oscar Perpiñán). split= takes a vector of four numbers. The vector's 3rd and 4th elements give the number of columns and rows in the display, while its 1st and 2nd elements give the column- and row-positions of the object being printed.

library(gridExtra)
p1 <- levelplot(r1)
p2 <- levelplot(r2)
print(p1, split=c(1,1,2,1), more=TRUE)
print(p2, split=c(2,1,2,1))

这篇关于多个(rasterVis)水平图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆