Helper function to make a ggplot2 layer from data returned by
get_location_data()
. For text geoms, the required aesthetic mapping is
set based on the name_col but values passed to mapping take precedence.
Usage
layer_location_data(
mapping = NULL,
data = NULL,
geom = "sf",
location = NULL,
dist = getOption("overedge.dist"),
diag_ratio = getOption("overedge.diag_ratio"),
unit = getOption("overedge.unit", default = "meter"),
asp = getOption("overedge.asp"),
package = getOption("overedge.data_package"),
filetype = getOption("overedge.data_filetype"),
fn = NULL,
geom_fn = NULL,
crop = TRUE,
trim = FALSE,
from_crs = getOption("overedge.from_crs"),
crs = getOption("overedge.crs"),
label_col = "name",
...
)
Arguments
- mapping
Set of aesthetic mappings created by
aes()
oraes_()
. If specified andinherit.aes = TRUE
(the default), it is combined with the default mapping at the top level of the plot. You must supplymapping
if there is no plot mapping.- data
Character string (e.g. url, file path, or name of data from package), a
sf
,sfc
, orbbox
object including data in area.- geom
A character string indicating which ggplot2 geom to use, Default: 'sf'. Options include "sf" (ggplot2::geom_sf), "icon" (layer_icon), "markers" (layer_markers), "text" (ggplot2::geom_sf_text), and "label" (ggplot2::geom_sf_label). See details for a full list.
- location
sf object. If multiple areas are provided, they are unioned into a single sf object using sf::st_union
- dist
buffer distance in units. Optional.
- diag_ratio
ratio of diagonal distance of area's bounding box used as buffer distance. e.g. if the diagonal distance is 3000 meters and the "diag_ratio = 0.1" a 300 meter will be used. Ignored when
dist
is provided.- unit
unit to adjust location by dist or diag_ratio; defaults to "meter"
- asp
Aspect ratio of width to height as a numeric value (e.g. 0.33) or character (e.g. "1:3"). If numeric,
get_asp()
returns the same value without modification.- package
Name of the package to search for data.
- filetype
File type to use if passing parameters to read_sf_download or read_sf_pkg (required for extdata and cached data).
- fn
Function to apply to data after filtering by location but before returning from function.
- geom_fn
ggplot2 geom or custom function using lambda syntax. Use for passing custom mapping functions to layer_location_data beyond the supported geom options.
- crop
If
TRUE
, data is cropped to location or bounding box sf::st_crop adjusted by thedist
,diag_ratio
, andasp
parameters provided. Default TRUE.- trim
If
TRUE
, data is trimmed to area with sf::st_intersection. This option ignores anydist
,diag_ratio
, orasp
parameters. DefaultFALSE
.- from_crs
Coordinate reference system used to match the location CRS to the source data.
- crs
Coordinate reference system to return.
- label_col
Column name or id for a column with the text or labels to pass to any text geom.
- ...
Parameters passed to selected geom
Details
Supported geom function options:
Options for the geom parameter from the overedge package include:
"icon" (layer_icon),
"mapbox" (layer_mapbox),
"markers" (layer_markers),
"numbers" (layer_numbers)
Options for the geom parameter from other packages include:
"textsf" (geomtextpath::geom_textsf)
"labelsf" (geomtextpath::geom_labelsf)
"text_repel" (ggrepel::geom_text_repel)
"label_repel" (ggrepel::geom_label_repel)
"mark" (birdseyeview::layer_show_mark)
"location" (birdseyeview::layer_show_location)
"context" (birdseyeview::layer_show_context)
"pattern" (ggpattern::geom_sf_pattern)
Alternatively, use the "geom_fn" parameter to pass a function that returns a ggplot2 layer to use instead of one of the preset geom functions.
See also
Other layer:
layer_frame()
,
layer_icon()
,
layer_markers()
,
layer_mask()
,
layer_neatline()
,
layer_scaled()