4

How to create and save inset maps with tmap is covered in several tutorials, e.g. here. However, I would like to merge several maps into one file, as facilitated by tmap_arrange. To my understanding, the way inset maps are created in tmap involves using grid::viewport, which plots additional objects on top of an existing plot. Unfortunately, this method does not seem to enable creating a named tmap-object which could be used in the tmap_arrange command. Is this just me, or did I miss something?

library(sf)
library(tidyverse)
library(tmaptools)
library(tmap)
library(grid)
library(raster)

DE <- getData('GADM', country='DE', level=0) %>% 
  st_as_sf() %>% 
  tm_shape + 
  tm_polygons()

BAV <- getData('GADM', country='DE', level=1) %>% 
  st_as_sf() %>% 
  filter(NAME_1 == "Bayern") %>% 
  tm_shape + 
  tm_polygons()

map_joined <- tmap_arrange(DE, BAV, ncol = 2)

BAV
print(DE, vp = viewport(0.85, 0.8, width = 0.2, height = 0.2)) 

#map_inset_joined <- tmap_arrange(???, DE, ncol = 2) does not work!
M.Teich
  • 575
  • 5
  • 22
  • 1
    I can't claim this solution for myself, as it was answered on github. Unfortunately, `tmap_arrange` does not support inset maps, so the maps need to be converted to grobs and arranged using `cowplot`. See [this link](https://github.com/mtennekes/tmap/issues/541) for the full answer – M.Teich Jan 22 '21 at 18:42

0 Answers0