Reputation: 11
I would like to merge multiple levelplots into one (using rasterVis package). I succeded in doing so with c() (see reprex). However, I cannot find a way to manage the titles of subplots. Specifically, only the top row plots get the right title while the rest get a very 'ugly' NA as subplot title.
# 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)
In my case, each column of the multiple levelplot contains subplots with the same title (season of the year, for different countries). Hence, I would be fine to have either: 1)'blank' titles for subplots from the 2nd row downwards or, 2) The same title for each subplot in each column
I am asking since I will automatize this procedure for around 400 plots, hence it would be very nice to have the right title/subtitle directly from the script.
What I was expecting was to have each subplot with the same title in each column (since the names in each single levelplots are correct). I also tried to set blank names for the second levelplot using
plot2 <- levelplot(c(r3,r4), names.attr=rep("",2))
Which worked when I print the single levelplot
print(plot2)
However, I got the same results ('NA' as subplot title) when I combine it togheter using c(). Any help is highly appreciated.
Upvotes: 0
Views: 143
Reputation: 4511
This is not exactly the solution you are looking for:
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))
I like it because it highlights the different extent of the rasters.
Upvotes: 0