Skip to contents

Add an inset within a map

Usage

add_inset(x, y, ratio = 1/5, add = TRUE, ...)

Arguments

x

should be a sf object or at least readable by sf::st_geometry.

y

should be a sf object or at least readable by sf::st_bbox.

ratio

numeric, how big should be the inset relative to the whole map or to y. See details.

add

loical, should the inset be added to an existing plot.

...

some parameters that will be used by sf::plot

Value

sf geometry transformed to be placed in the good loaction in the map.

Details

If add = TRUE, the location is calculated through the extent of current map. If add = FALSE, the location is calcultaed through the extent of y.

The function is based on the facility to rescale and translate sf object.

Author

Frédéric Grelot

Examples


library(sf)
#> Linking to GEOS 3.12.2, GDAL 3.10.3, PROJ 9.4.1; sf_use_s2() is TRUE
so.ii::map_so_ii()
inset = add_inset(
  so.ii::so_ii_inset[c("region", "so-ii"), ],
  so.ii::so_ii_limit,
  col = c("gray", "red"), border = c(NA, "red"), lwd = 1:2
)