管理多个(rasterVis)水平图中的子图标题

问题描述 投票:0回答:1

我想将多个水平图合并为一个(使用 rasterVis 包)。我用 c() 成功地做到了这一点(参见 reprex)。但是,我找不到管理子图标题的方法。具体来说,只有最上面一行的图获得了正确的标题,而其余的获得了一个非常“丑陋”的 NA 作为子图标题。

# Load libraries
library(rasterVis)
library(terra)

# Create raster extents
bbox_italy <- c(6.284180,19.028320,36.385913,47.398349) # Bounding box Italy
bbox_greece <- c(19.006348,29.245605,34.107256,42.098222) # Bounding box greece 

# Create raster data
# Greece spring
r1 <- rast(ncol=10, nrow=10, ext(bbox_greece))  
r1 <- setValues(r1, 1:ncell(r1))
names(r1) <- 'spring'
# Greece summer
r2 <- rast(ncol=10, nrow=10, ext(bbox_greece)) 
r2 <- setValues(r2, 1:ncell(r2))
names(r2) <- 'summer'

# Italy spring
r3 <- rast(ncol=10, nrow=10, ext(bbox_italy))  
r3 <- setValues(r3, 1:ncell(r3))
names(r3) <- 'spring'
#italy summer
r4 <- rast(ncol=10, nrow=10, ext(bbox_italy)) 
r4 <- setValues(r4, 1:ncell(r4))
names(r4) <- 'summer'


# create levelplots 
plot1 <- levelplot(c(r1, r2))
plot2 <- levelplot(c(r3,r4))

# combine level plots
comb_plot <- c(plot1, plot2, layout = c(2, 2), merge.legends = F)
print(comb_plot)

在我的例子中,多层次图的每一列都包含具有相同标题的子图(一年中的季节,针对不同的国家)。因此,我可以选择: 1)从第二行向下的子图的“空白”标题,或者, 2)每列中每个子图的标题相同

我在问,因为我将为大约 400 个地块自动执行此过程,因此直接从脚本中获得正确的标题/副标题会非常好。

我期望的是每个子图在每一列中都有相同的标题(因为每个单层图中的名称都是正确的)。 我还尝试使用

为第二级图设置空白名称
plot2 <- levelplot(c(r3,r4), names.attr=rep("",2))

当我打印单层图时它起作用了

print(plot2)

但是,当我使用 c() 将它组合在一起时,我得到了相同的结果('NA' 作为子图标题)。 非常感谢任何帮助。

r names levelplot rastervis
1个回答
0
投票

这不是您正在寻找的解决方案:

plot1 <- levelplot(c(r1, r2))
plot2 <- levelplot(c(r3,r4))

print(plot1, split = c(1,1, 1, 2), more = TRUE)
print(plot2, split = c(1,2, 1, 2))

我喜欢它,因为它突出了栅格的不同程度。

© www.soinside.com 2019 - 2024. All rights reserved.