geom_sf_inset {ggmapinset} | R Documentation |
Visualise sf objects with insets
Description
These geoms are wrappers around ggplot2::geom_sf()
and its relatives that
assist with creating map insets.
In many cases all that is needed is to use coord_sf_inset()
with configure_inset()
to configure the location and transformation of the inset, and then replace the
sf-related geoms with their _inset
counterparts.
Use geom_inset_frame()
to add a frame around the inset that connects it to the main map.
Usage
geom_sf_inset(
mapping = ggplot2::aes(),
data = NULL,
stat = "sf_inset",
position = "identity",
...,
inset = NA,
map_base = "normal",
map_inset = "auto",
na.rm = TRUE,
show.legend = NA,
inherit.aes = TRUE
)
geom_sf_text_inset(
mapping = aes(),
data = NULL,
stat = "sf_coordinates_inset",
position = "identity",
...,
where = "inset",
parse = FALSE,
check_overlap = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
fun.geometry = NULL
)
geom_sf_label_inset(
mapping = aes(),
data = NULL,
stat = "sf_coordinates_inset",
position = "identity",
...,
where = "inset",
parse = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
fun.geometry = NULL
)
stat_sf_inset(
mapping = ggplot2::aes(),
data = NULL,
geom = "sf_inset",
position = "identity",
...,
inset = NA,
na.rm = TRUE,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
mapping , data , stat , geom , position , na.rm , show.legend , inherit.aes , ... |
See |
inset |
Inset configuration; see |
map_base |
Controls the layer with the base map. Possible values are
|
map_inset |
Controls the layer with the inset map. Possible values are
|
where |
Specifies how the text position interacts with the inset.
|
parse |
If |
check_overlap |
If |
fun.geometry |
A function that takes a |
Details
Internally this works by creating two layers: one for the base map, and one
for the inset. These can be separately controlled by the map_base
and
map_inset
parameters. If inset
is not specified, this geom will instead
behave like ggplot2::geom_sf()
.
When an inset is configured, the default creates both base and inset layers using the same aesthetic mapping and params:
geom_sf_inset(...)
You can alternatively specify the two layers separately:
# draw the base map only (both versions are equivalent): geom_sf(...) geom_sf_inset(..., map_inset = "none") # separately, draw the inset map only: geom_sf_inset(..., map_base = "none")
stat_sf_inset()
works the same ggplot2::stat_sf()
except that it also
expands the axis limits to account for the inset area.
Value
A ggplot layer similar to ggplot2::geom_sf()
but transformed according to the
inset configuration.
Examples
library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
geom_sf_inset(aes(fill = AREA)) +
geom_inset_frame() +
coord_sf_inset(inset = configure_inset(
centre = sf::st_sfc(sf::st_point(c(-80, 35.5)), crs = sf::st_crs(nc)),
scale = 1.5, translation = c(-50, -140), radius = 50, units = "mi"))