
Use patchwork to create a map with an inset context map or figpatch to stamp an inset image
Source:R/layer_inset.R
layer_inset.Rdlayer_inset() is useful when you want to add an inset to a plot.
Usage
layer_inset(
map = NULL,
inset = NULL,
position = "bottomright",
scale = 1,
nudge_x = 0,
nudge_y = 0,
align_to = "full",
...
)
make_inset_map(
map = NULL,
inset = NULL,
location = NULL,
context = NULL,
position = "bottomright",
scale = 1,
nudge_x = 0,
nudge_y = 0,
align_to = "full",
...
)
stamp_inset_img(
path,
plot = NULL,
img_margin = ggplot2::margin(0, 0, 0, 0),
position = "bottomright",
scale = 1,
nudge_x = 0,
nudge_y = 0,
align_to = "full",
...
)Arguments
- inset
plot or map created with
ggplot2()passed to p argument ofpatchwork::inset_element(). If both location and context are provided tomake_inset_map(), inset is optional and any provided value is replaced with a new layer created bylayer_location_context().- position
inset map position, Default: 'bottomright'. position, nudge_x, and nudge_y are used to set the left, bottom, top, and right parameters for
patchwork::inset_element().- scale
scale of inset map, defaults to 1.
- nudge_x, nudge_y
nudge x and/or y position of inset map, Default: 0.
- align_to
Specifies what
left,bottom, etc should be relative to. Either'panel'(default),'plot', or'full'.- ...
Arguments passed on to
patchwork::inset_elementpA grob, ggplot, patchwork, formula, raster, or nativeRaster object to add as an inset
left,bottom,right,topnumerics or units giving the location of the outer bounds. If given as numerics they will be converted to
npcunits.on_topLogical. Should the inset be placed on top of the other plot or below (but above the background)?
clipLogical. Should clipping be performed on the inset?
ignore_tagLogical. Should autotagging ignore the inset?
- location
A location passed to
layer_location_context(). This can be a sf object, a ggplot layer, or a formula or function. If it is a formula or function, it is applied to the context data is passed to the location function and the results used as the data for the location layer.- context
A
sfobject for context area or a ggplot layer representing the context.- path
image path passed to
figpatch::fig()forstamp_inset_img()- plot, map
plot or map created with
ggplot2()- img_margin
margin around image for
stamp_inset_img()created byggplot2::margin(). Defaults to no margin.
Details
make_inset_map() is useful for creating an inset map just using the
location with fewer options for customization. In that case, the ...
parameters are passed to layer_location_context() instead of
patchwork::inset_element()
stamp_inset_img() is useful for applying a logo to a map. The ...
parameters are passed to figpatch::fig()
Note, currently, plots created with layer_inset() do not work with
map_ggsave_ext() using the single_file = TRUE parameter.