rasterVis-使用levelplot在中间设置底部图 [英] rasterVis - setting the bottom plots in the middle with levelplot

查看:92
本文介绍了rasterVis-使用levelplot在中间设置底部图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用令人敬畏的 rasterVis 创建一个面板,其中包含具有相同范围(即相同的空间覆盖率)但显示不同特征(即每个都有其自己的图例)的地图.

这是到目前为止的样子:

 库(光栅)图书馆(rasterVis)库(RColorBrewer)图书馆(gridExtra)#化妆数据r<-raster(system.file("external/test.grd",package ="raster"))s<-stack(r,r * 2,r * 3,r * 4,r * 5)名称<-paste0(字段",seq(1,5))#预分配列表1<-vector(列表",length = nlayers)#定义情节的主题my.theme<-rasterTheme(region = brewer.pal(11,'RdYlGn'))#遍历堆栈层以填充列表for(n in(1:nlayers(s))){l [[n]] <-levelplot(s [[n]],margin = F,main = names(s [[n]]),par.settings = my.theme)}# 绘制组合地图grid.arrange(l [[1]],l [[2]],l [[3]],l [[4]],l [[5]],ncol = 3) 

请注意,地图的默认位置是:

  a b ce 

但是,我希望对定位进行更好的控制.具体而言,我想以居中"为准.底部的两个小平面,以便在图的侧面更均匀地分布空隙空间.

换句话说,我要查找的展示位置如下所示:

  a b ce 

我该如何实现?我查看了(

您可以在底部的 plot_grid 调用中修改 rel_widths 来获取它.

I am using the awesome rasterVis to create a panel with maps that have the same extent (i.e. same spatial coverage) but that show different features (i.e. each with its own legend).

This is what it looks like so far:

library(raster)
library(rasterVis)
library(RColorBrewer)
library(gridExtra)

# make-up data
r <- raster(system.file("external/test.grd", package="raster"))
s <- stack(r, r*2, r*3, r*4, r*5)
names(s) <- paste0("Field ",seq(1,5))

# pre-allocate list
l <- vector("list", length=nlayers(s))

# define theme for plots
my.theme <- rasterTheme(region=brewer.pal(11,'RdYlGn'))

# loop over stack layers to fill list
for (n in (1:nlayers(s))){
  
  l[[n]] <- levelplot(s[[n]], margin=F, main=names(s[[n]]), par.settings=my.theme)
  
}

# plot combined maps
grid.arrange(l[[1]], l[[2]], l[[3]], l[[4]], l[[5]], ncol=3)

Note that the default positioning for the maps is:

a b c
d e

However, I would like to have a finer control on the positioning. Specifically, I would like to "center" the bottom two facets in order to distribute the void space more evenly on the sides of the plot.

In other words, the placement I am looking for would look like:

a b c
 d e

How can I achieve this? I looked up the documentation for (grid.arrange), but couldn't find any option the would solve my problem.

Thanks in advance for any hints.

解决方案

Here's an approach with cowplot::plot_grid inspired by this answer

library(cowplot)
top <- plot_grid(l[[1]], l[[2]], l[[3]],
                 ncol=3)
bottom <- plot_grid(NULL, l[[4]], NULL,  l[[5]], NULL,
                    ncol=6, rel_widths=c(0.12,0.34,0.12,0.34,0.06))
plot_grid(top, bottom,
          ncol=1, rel_heights=c(1,1))

You can modify the rel_widths in the bottom plot_grid call to get it just like you like.

这篇关于rasterVis-使用levelplot在中间设置底部图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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