9.7 Inset Maps
map_nz3
An area of interest may be difficult to see at first.
# define area of interest
= st_bbox(c(xmin = 1340000, xmax = 1450000,
nz_region ymin = 5130000, ymax = 5210000),
crs = st_crs(nz_height)) |>
st_as_sfc()
# create inset map
= tm_shape(nz_elev, bbox = nz_region) +
nz_height_map tm_raster(style = "cont", palette = "YlGn", legend.show = TRUE) +
tm_shape(nz_height) + tm_symbols(shape = 2, col = "red", size = 1) +
tm_scale_bar(position = c("left", "bottom"))
# create basemap
= tm_shape(nz) + tm_polygons() +
nz_map tm_shape(nz_height) + tm_symbols(shape = 2, col = "red", size = 0.1) +
tm_shape(nz_region) + tm_borders(lwd = 3)
# display result
nz_height_mapprint(nz_map, vp = viewport(0.8, 0.27, width = 0.5, height = 0.5))
Here is another example with the United States
= tm_shape(us_states, projection = "EPSG:2163") + tm_polygons() +
us_states_map tm_layout(frame = FALSE)
= tm_shape(hawaii) + tm_polygons() +
hawaii_map tm_layout(title = "Hawaii", frame = FALSE, bg.color = NA,
title.position = c("LEFT", "BOTTOM"))
= tm_shape(alaska) + tm_polygons() +
alaska_map tm_layout(title = "Alaska", frame = FALSE, bg.color = NA)
us_states_mapprint(hawaii_map, vp = grid::viewport(0.35, 0.1, width = 0.2, height = 0.1))
print(alaska_map, vp = grid::viewport(0.15, 0.15, width = 0.3, height = 0.3))