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!