Title: | Make Map Layers With ggplot2 |
---|---|
Description: | Make map-making with ggplot2 and sf more convenient with layers that subset by location. |
Authors: | Eli Pousson [aut, cre, cph] |
Maintainer: | Eli Pousson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9003 |
Built: | 2024-11-06 05:30:26 UTC |
Source: | https://github.com/elipousson/maplayer |
A helper function that converts strings to glue strings for the title, subtitle, and caption.
labs_ext( ..., title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), tag = ggplot2::waiver(), alt = ggplot2::waiver(), alt_insight = ggplot2::waiver(), source_note = NULL, source_sep = ". ", source_before = "Source: ", source_end = ".", .sep = "", .envir = parent.frame(), .open = "{", .close = "}", .na = "NA", .null = character(), .comment = "#", .literal = FALSE, .transformer = glue::identity_transformer, .trim = TRUE )
labs_ext( ..., title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), tag = ggplot2::waiver(), alt = ggplot2::waiver(), alt_insight = ggplot2::waiver(), source_note = NULL, source_sep = ". ", source_before = "Source: ", source_end = ".", .sep = "", .envir = parent.frame(), .open = "{", .close = "}", .na = "NA", .null = character(), .comment = "#", .literal = FALSE, .transformer = glue::identity_transformer, .trim = TRUE )
... |
Arguments passed on to
|
title |
The text for the title. |
subtitle |
The text for the subtitle for the plot which will be displayed below the title. |
caption |
The text for the caption which will be displayed in the bottom-right of the plot by default. |
tag |
The text for the tag label which will be displayed at the top-left of the plot by default. |
alt , alt_insight
|
Text used for the generation of alt-text for the plot. See get_alt_text for examples. |
source_note |
Data source(s) to append to caption or use as caption (if no caption is supplied). Also supports glue string interpolation. |
source_sep , source_before , source_end
|
Strings used to separate caption (if supplied) and source note, add before the source note, and add after the source note. |
.sep |
[ |
.envir |
[ |
.open |
[ |
.close |
[ |
.na |
[ |
.null |
[ |
.comment |
[ |
.literal |
[ |
.transformer |
[ |
.trim |
[ |
A wrapper for ggplot2::geom_segment, ggplot2::geom_curve()
,
ggarchery::geom_arrowsegment()
, ggforce::geom_diagonal0()
,
ggforce::geom_link()
that makes it easier to specify the start and end of
the segment using any object supported by the sfext::as_xy()
function.
layer_arrow( mapping = NULL, data = NULL, crs = NULL, from, to, geom = "segment", ... )
layer_arrow( mapping = NULL, data = NULL, crs = NULL, from, to, geom = "segment", ... )
mapping |
aesthetic mapping overwritten with x, y, xend, and yend values based on provided from and to parameters. |
data |
Required if from or to are character vectors to |
crs |
A character or numeric reference to a coordinate reference system
supported by |
from , to
|
Required. Passed to x parameter of |
geom |
Character string for geom to use c("segment", "curve", "arrowsegment", "diagonal0", "link") or a geom function. |
... |
Additional parameters passed to function specified by geom paramter. |
ggplot2::reexports()
, ggplot2::geom_segment()
, ggplot2::aes()
library(ggplot2) nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc_map <- ggplot(data = nc) + geom_sf() nc_map + layer_arrow( data = nc, from = c("xmin", "ymin"), to = c("xmid", "ymax"), ) nc_map + layer_arrow( data = nc, from = c("xmin", "ymin"), to = c("xmid", "ymax"), geom = "curve", curvature = 0.25 ) nc_map + layer_arrow( data = nc, from = c("xmax", "ymin"), to = c("xmid", "ymax"), geom = "arrowsegment" )
library(ggplot2) nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc_map <- ggplot(data = nc) + geom_sf() nc_map + layer_arrow( data = nc, from = c("xmin", "ymin"), to = c("xmid", "ymax"), ) nc_map + layer_arrow( data = nc, from = c("xmin", "ymin"), to = c("xmid", "ymax"), geom = "curve", curvature = 0.25 ) nc_map + layer_arrow( data = nc, from = c("xmax", "ymin"), to = c("xmid", "ymax"), geom = "arrowsegment" )
Wraps sfext::count_sf_ext()
. Specification of parameters for this function
may be too complex and may be changed in the future.
layer_count( data, location = NULL, y = NULL, join = sf::st_intersects, largest = TRUE, replace_na = FALSE, lims = NULL, .id = "id", grid_params = list(alpha = 1, color = NA), show_data = FALSE, data_params = list(mapping = aes(), alpha = 0.75, size = 1), show_label = FALSE, label_params = NULL, scale_fn = ggplot2::scale_fill_continuous, scale_params = list(type = "viridis", breaks = scales::breaks_pretty(n = 4)), ... )
layer_count( data, location = NULL, y = NULL, join = sf::st_intersects, largest = TRUE, replace_na = FALSE, lims = NULL, .id = "id", grid_params = list(alpha = 1, color = NA), show_data = FALSE, data_params = list(mapping = aes(), alpha = 0.75, size = 1), show_label = FALSE, label_params = NULL, scale_fn = ggplot2::scale_fill_continuous, scale_params = list(type = "viridis", breaks = scales::breaks_pretty(n = 4)), ... )
data |
Data to count in relationship to y |
location |
Passed to x parameter of |
y |
If |
join |
geometry predicate function with the same profile as st_intersects; see details |
largest |
logical; if |
replace_na |
If |
lims |
Optional numeric vector with minimum or both minimum and maximum count values. If provided, any values below the minimum are set to that minimum and any values above the maximum as set to the maximum. If only one value is provided, it is assumed to be a minimum limit. |
.id |
A name to use for the cell id column. Defaults to "id". |
grid_params |
Passed to |
show_data |
If |
data_params |
Passed to |
show_label |
If |
label_params |
Passed to |
scale_fn , scale_params
|
Scale function and parameters. Defaults to
|
... |
Arguments passed on to
|
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) data <- sf::st_sample(nc, 75) ggplot() + layer_count(data = data, location = nc) ggplot() + layer_count(data = data, y = nc, .id = "FIPS")
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) data <- sf::st_sample(nc, 75) ggplot() + layer_count(data = data, location = nc) ggplot() + layer_count(data = data, y = nc, .id = "FIPS")
Create a circle or square that can be used as a frame around a simple feature
object using fixed aesthetics for fill, color, size, and linetype. This
function is helpful for the background of an inset map intended for use with
layer_inset()
.
layer_frame( data = NULL, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style = "circle", scale = 1, rotate = 0, inscribed = FALSE, color = "black", linewidth = 0.5, linetype = "solid", fill = "white", neatline = TRUE, expand = TRUE, basemap = FALSE, union = TRUE, by_feature = FALSE, ... ) make_frame( x, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style = "circle", scale = 1, rotate = 0, inscribed = FALSE, dTolerance = 0, union = TRUE, by_feature = FALSE )
layer_frame( data = NULL, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style = "circle", scale = 1, rotate = 0, inscribed = FALSE, color = "black", linewidth = 0.5, linetype = "solid", fill = "white", neatline = TRUE, expand = TRUE, basemap = FALSE, union = TRUE, by_feature = FALSE, ... ) make_frame( x, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style = "circle", scale = 1, rotate = 0, inscribed = FALSE, dTolerance = 0, union = TRUE, by_feature = FALSE )
data , x
|
A |
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 |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; 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, |
style |
Style of framing shape to add, "circle", "square", "rect", "buffer", or "none". If style is "buffer", the asp parameter is ignored. If style is "none", the dist, diag_ratio, and asp parameters are ignored and the input data is used as the frame. |
scale |
numeric; scale factor, Default: 1 |
rotate |
numeric; degrees to rotate (-360 to 360), Default: 0 |
inscribed |
If |
fill , color , linewidth , linetype
|
Fixed aesthetics for frame, passed to layer_location_data. |
neatline |
If |
expand |
If |
basemap |
Either a logical vector or ggplot object. If logical and If a ggplot, add x to basemap object. If a ggproto object (or list that contains a ggproto object), add x
and basemap object to |
union |
If |
by_feature |
If |
... |
Arguments passed on to
|
dTolerance |
numeric; tolerance parameter, specified for all or for each
feature geometry. If you run |
The make_frame()
helper function calls sfext::st_circle()
(if style = "circle"
), sfext::st_square()
(if style = "square"
),
sfext::st_bbox_ext()
(if style = "rect"
), or sfext::st_buffer_ext()
(if
style = "none"
).
If neatline is TRUE
, layer_frame()
returns a list of two geoms, the
second a layer_neatline()
layer created using the frame object as the data
and the parameters bgcolor = "none"
and color = "none"
. asp is set to 1
if style is "circle" or "square" or the provided asp value otherwise.
Additional parameters passed through ... can include additional fixed
aesthetics (e.g. alpha). If using the fn parameter, the function is applied
to the frame simple feature object created by make_frame()
(not to the
original input data).
Other layer:
layer_location_data()
,
layer_neatline()
,
layer_scaled()
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) raleigh_msa <- getdata::get_location( type = nc, name_col = "NAME", name = c("Franklin", "Johnston", "Wake"), crs = 3857 ) ggplot() + layer_frame( data = raleigh_msa, frame = "circle", fill = "lightyellow", inscribed = FALSE ) + layer_location_data( data = raleigh_msa, mapping = aes(fill = NAME), alpha = 0.5 ) + ggplot2::guides( fill = "none" )
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) raleigh_msa <- getdata::get_location( type = nc, name_col = "NAME", name = c("Franklin", "Johnston", "Wake"), crs = 3857 ) ggplot() + layer_frame( data = raleigh_msa, frame = "circle", fill = "lightyellow", inscribed = FALSE ) + layer_location_data( data = raleigh_msa, mapping = aes(fill = NAME), alpha = 0.5 ) + ggplot2::guides( fill = "none" )
Can be used to make multiple layers or multiple maps based on a grouping variable.
layer_grouped( data, mapping = NULL, groupname_col = "group", label_col = "name", geom = "sf", basemap = FALSE, palette = NULL, aesthetics = "fill", ... )
layer_grouped( data, mapping = NULL, groupname_col = "group", label_col = "name", geom = "sf", basemap = FALSE, palette = NULL, aesthetics = "fill", ... )
data |
Character string (e.g. url, file path, or name of data from
package) for a spatial data or a |
mapping |
Set of aesthetic mappings created by |
groupname_col |
Group column name. Defaults to "group". |
label_col |
Column name or id for a column with the text or labels to pass to any text geom. |
geom |
A character string indicating which ggplot2 geom to use, Default:
'sf'. Options include "sf" ( |
basemap |
Either a logical vector or ggplot object. If logical and If a ggplot, add x to basemap object. If a ggproto object (or list that contains a ggproto object), add x
and basemap object to |
palette |
Name of palette as a string. Must be on the form packagename::palettename. |
aesthetics |
Aesthetic to map to groupname_col. Defaults to "fill"; also supports "color" or c("fill", "color"). |
... |
Additional parameters passed to |
Scales are applied a palette and aesthetic are provided and basemap is set to
TRUE
.
Use the ggsvg::geom_point_svg()
function to plot icons using the centroids
from the input simple feature object to set the icon location.
layer_icon( data = NULL, iconname_col = "icon", icon = NULL, px = NULL, source = NULL, svg = NULL, crs = getOption("maplayer.crs", default = 3857), ... ) geom_sf_icon( data = NULL, iconname_col = "icon", icon = NULL, px = NULL, source = NULL, svg = NULL, crs = getOption("maplayer.crs", default = 3857), ... )
layer_icon( data = NULL, iconname_col = "icon", icon = NULL, px = NULL, source = NULL, svg = NULL, crs = getOption("maplayer.crs", default = 3857), ... ) geom_sf_icon( data = NULL, iconname_col = "icon", icon = NULL, px = NULL, source = NULL, svg = NULL, crs = getOption("maplayer.crs", default = 3857), ... )
data |
A |
iconname_col |
The column name in the input data to use as the icon
name. If the name matches multiple icons, the first match from |
icon |
Icon name. Default |
px |
Icon size in pixels. See |
source |
Icon source. See |
svg |
Optional. Custom file path or URL with SVG to pass to |
crs |
Coordinate reference system; defaults to |
... |
Arguments passed on to
|
ggsvg::geom_point_svg()
map_icons
nc <- getdata::get_location(type = system.file("shape/nc.shp", package = "sf"), crs = 3857) basemap <- ggplot2::ggplot() + ggplot2::theme_void() + layer_location_data(data = nc) # icon can be set by name matching a name from map_icons basemap + layer_icon(data = nc, icon = "point-start", size = 8) # layer_icon can also use a column from the sf object nc$icon <- rep(c("1", "2", "3", "4"), nrow(nc) / 4) basemap + layer_icon(data = nc, iconname_col = "icon", size = 6)
nc <- getdata::get_location(type = system.file("shape/nc.shp", package = "sf"), crs = 3857) basemap <- ggplot2::ggplot() + ggplot2::theme_void() + layer_location_data(data = nc) # icon can be set by name matching a name from map_icons basemap + layer_icon(data = nc, icon = "point-start", size = 8) # layer_icon can also use a column from the sf object nc$icon <- rep(c("1", "2", "3", "4"), nrow(nc) / 4) basemap + layer_icon(data = nc, iconname_col = "icon", size = 6)
Use the ggpath::geom_from_path()
function with sfext::read_sf_exif()
and
stat = "sf_coordinates"
to create a layer showing images at locations.
layer_image_path( data = NULL, path = NULL, path_col = "path", width = 0.1, crs = getOption("maplayer.crs", 3857), segment_params = NULL, neatline = FALSE, basemap = FALSE, ... )
layer_image_path( data = NULL, path = NULL, path_col = "path", width = 0.1, crs = getOption("maplayer.crs", 3857), segment_params = NULL, neatline = FALSE, basemap = FALSE, ... )
data |
A |
path |
A path to folder or file. |
path_col |
Column name with file paths from data. Defaults to "path"
(path name used by data returned from |
width |
Width of the image in npc (Normalised Parent Coordinates) passed
to |
crs |
The coordinate reference system (CRS) into which all data should be projected before plotting. If not specified, will use the CRS defined in the first sf layer of the plot. |
segment_params |
Not implemented: parameters to define segments connecting images to the location. |
neatline |
A logical object,
|
basemap |
Either a logical vector or ggplot object. If logical and If a ggplot, add x to basemap object. If a ggproto object (or list that contains a ggproto object), add x
and basemap object to |
... |
Additional parameters to pass to |
layer_inset()
is useful when you want to add an inset to a plot.
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", ... )
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", ... )
inset |
plot or map created with |
position |
inset map position, Default: 'bottomright'. position,
nudge_x, and nudge_y are used to set the left, bottom, top, and right
parameters for |
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 |
... |
Arguments passed on to
|
location |
A location passed to |
context |
A |
path |
image path passed to |
plot , map
|
plot or map created with |
img_margin |
margin around image for |
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.
ggplot2 map with inset map added using patchwork
Label markers, streets, areas, or other simple feature objects using any of the following geoms: "text", "sf_text", "label", "sf_label", "textsf", "labelsf", "text_repel", or "label_repel".
layer_labelled( data, location = NULL, geom = "text", fn = NULL, label_col = NULL, mapping = NULL, union = FALSE, clip = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, drop_shadow = FALSE, shadow_params = NULL, ... )
layer_labelled( data, location = NULL, geom = "text", fn = NULL, label_col = NULL, mapping = NULL, union = FALSE, clip = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, drop_shadow = FALSE, shadow_params = NULL, ... )
data |
Data to use for labels (must be an sf object or a data frame that
can be converted to an sf object using |
location |
Location to label (if not specified the data is assumed to conver the whole location); |
geom |
A geom to use "text", "label", "textsf", "labelsf", "text_repel", or "label_repel" or a geom function (passed to layer_fn). |
fn |
Function to apply to data before creating labels; can be used in the creation of the label_col. |
label_col |
Label column name |
mapping |
Aesthetic mapping, Default: |
union |
If TRUE, group by label_col and union geometry, Default: |
clip |
Character string describing the part of the area to clip or remove. Options include c("top", "right", "bottom", "left", "topright", "bottomright", "bottomleft", "topleft"). If NULL, the area is not clipped and a full edge can be returned. |
dist |
Numeric. Distance to use for the edge. Default NULL meters. Use negative values for an inside edge or positive numbers for an outside edge. |
diag_ratio |
Alternate way to define edge distance. |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; defaults to "meter" |
drop_shadow |
If |
shadow_params |
Parameters passed to |
... |
Arguments passed on to
|
Note: Unlike in some getdata package functions, fn is applied to all of the
data; not a subset of the data based on location. For this function, dist and
unit are both used by sfext::st_clip()
(not by layer_location_data()
)
The function also overrides the label aesthetics to hide the colored letters that would otherwise appear when using a theme legend.
sfext::st_clip()
,layer_location_data()
Helper function to make a ggplot2 layer from data returned by
get_location
layer_location( mapping = ggplot2::aes(), data = NULL, type = NULL, name = NULL, id = NULL, location = NULL, name_col = "name", id_col = "id", index = NULL, label = NULL, label_geom = NULL, label_col = name_col, union = FALSE, crs = getOption("maplayer.crs", default = 3857), color = "gray40", linewidth = 0.5, linetype = "dashed", fill = NA, alpha = 1, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, mask = FALSE, neatline = FALSE, smooth_params = NULL, shadow_params = NULL, ... )
layer_location( mapping = ggplot2::aes(), data = NULL, type = NULL, name = NULL, id = NULL, location = NULL, name_col = "name", id_col = "id", index = NULL, label = NULL, label_geom = NULL, label_col = name_col, union = FALSE, crs = getOption("maplayer.crs", default = 3857), color = "gray40", linewidth = 0.5, linetype = "dashed", fill = NA, alpha = 1, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, mask = FALSE, neatline = FALSE, smooth_params = NULL, shadow_params = NULL, ... )
mapping |
Set of aesthetic mappings created by |
data |
Data for location to show. |
type |
Type of location to return. Type can be an sf object, e.g. a data
frame with multiple neighborhoods or a character string that can be passed
to |
name |
Location name to return. |
id |
Location id to return. id is coerced to character or numeric to match the class of the id_col for type. |
location |
An address, bounding box ( |
name_col |
Column name in type with name values, Default: 'name' Required if name provided. |
id_col |
Column name in type with id values, Default: 'id'. Required if id is provided. |
index |
Optional list used to match type to data, Default: |
label |
label type (e.g. "text", "label") |
label_geom |
Optional character string or function with geom to use for
labelling location layer. Passed to geom parameter of |
label_col |
Column name or id for a column with the text or labels to pass to any text geom. |
union |
If |
crs |
Coordinate reference system to return; defaults to |
color |
Color for location; defaults to "black". |
linewidth |
Line width for location; defaults to 0.5. |
linetype |
Line type for location; defaults to "dashed". |
fill |
Fill for location; defaults to "NA". |
alpha |
mask alpha/transparency; defaults to 0.5 |
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 |
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, |
mask |
A |
neatline |
A logical object,
|
smooth_params |
Optional. Logical or a list of parameters passed to
|
shadow_params |
Optional. Logical or a list of parameters passed to
|
... |
Additional parameters passed to get_location if data is |
list of ggplot2 geoms
Create a ggplot2 layer for a location in a provided context. This function is useful for making inset locator maps in combination with the make_inset_map function.
layer_location_context( data = NULL, location = NULL, fill = "gray70", color = "black", context = NULL, context_params = list(fill = "white", color = "black", alpha = 1, ...), crs = getOption("maplayer.crs", default = 3857), mid_layer = NULL, neatline = TRUE, basemap = FALSE, ... )
layer_location_context( data = NULL, location = NULL, fill = "gray70", color = "black", context = NULL, context_params = list(fill = "white", color = "black", alpha = 1, ...), crs = getOption("maplayer.crs", default = 3857), mid_layer = NULL, neatline = TRUE, basemap = FALSE, ... )
data , location
|
A data and location can be a either |
fill , color
|
Fill and color fixed aesthetics for location data. |
context |
A |
context_params |
A list with parameters for context layer; defaults to
|
crs |
Coordinate reference system to return. |
mid_layer |
A ggplot2 layer to insert between the context layer and the location layer. Optional. |
neatline |
A logical object,
|
basemap |
Either a logical vector or ggplot object. If logical and If a ggplot, add x to basemap object. If a ggproto object (or list that contains a ggproto object), add x
and basemap object to |
... |
Additional parameters passed to |
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.
layer_location_data( mapping = NULL, data = NULL, geom = "sf", location = NULL, dist = getOption("maplayer.dist"), diag_ratio = getOption("maplayer.diag_ratio"), unit = getOption("maplayer.unit", default = "meter"), asp = getOption("maplayer.asp"), package = getOption("maplayer.data_package"), pkg = getOption("maplayer.data_package"), fileext = getOption("maplayer.data_fileext", "gpkg"), filetype = NULL, fn = NULL, layer_fn = NULL, crop = TRUE, trim = FALSE, from_crs = getOption("maplayer.from_crs", 4326), crs = getOption("maplayer.crs", 3857), label_col = "name", smooth_params = NULL, shadow_params = NULL, basemap = FALSE, ... )
layer_location_data( mapping = NULL, data = NULL, geom = "sf", location = NULL, dist = getOption("maplayer.dist"), diag_ratio = getOption("maplayer.diag_ratio"), unit = getOption("maplayer.unit", default = "meter"), asp = getOption("maplayer.asp"), package = getOption("maplayer.data_package"), pkg = getOption("maplayer.data_package"), fileext = getOption("maplayer.data_fileext", "gpkg"), filetype = NULL, fn = NULL, layer_fn = NULL, crop = TRUE, trim = FALSE, from_crs = getOption("maplayer.from_crs", 4326), crs = getOption("maplayer.crs", 3857), label_col = "name", smooth_params = NULL, shadow_params = NULL, basemap = FALSE, ... )
mapping |
Set of aesthetic mappings created by |
data |
Character string (e.g. url, file path, or name of data from
package) for a spatial data or a |
geom |
A character string indicating which ggplot2 geom to use, Default:
'sf'. Options include "sf" ( |
location |
sf object. If multiple areas are provided, they are unioned
into a single sf object using |
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 |
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, |
pkg , package
|
Name of the package to search for data. |
fileext , filetype
|
File extension or type to use if passing parameters
to |
fn |
Function to apply to data after filtering by location but before returning from function. |
layer_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 |
trim |
If |
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. |
smooth_params |
Optional. Logical or a list of parameters passed to
|
shadow_params |
Optional. Logical or a list of parameters passed to
|
basemap |
Either a logical vector or ggplot object. If logical and If a ggplot, add x to basemap object. If a ggproto object (or list that contains a ggproto object), add x
and basemap object to |
... |
Additional parameters passed to selected geom or layer_fn |
This function provides a convenient option for filtering data by location while calling a different layer function from ggplot2, maplayer, or a different package.
Options for the geom parameter from ggplot2:
"sf" (ggplot2::geom_sf - default)
"sf_text" or "text (ggplot2::geom_sf_text)
"sf_label" or "label (ggplot2::geom_sf_label)
Options for the geom parameter included in this package include:
"location" (layer_location)
"context" or "location_context" (layer_location_context)
"icon" (layer_icon),
"mapbox" (layer_mapbox)
"markers" (layer_markers)
"numbers" or "numbered" (layer_numbers)
"mark" or "marked" (layer_marked)
Options for the geom parameter from other suggested packages include:
"textsf" (geomtextpath::geom_textsf)
"labelsf" (geomtextpath::geom_labelsf)
"text_repel" (ggrepel::geom_text_repel)
"label_repel" (ggrepel::geom_label_repel)
"sf_pattern" or "pattern" (ggpattern::geom_sf_pattern)
stat = "sf_coordinates"
is automatically added to the parameters for both
ggrepel functions. label = .data[[name_col]]
is automatically added to all
provided geoms where label is a required parameter.
layer_fn can be a purrr-style lamba function (converted with
rlang::as_function()
) or a function.
Other layer:
layer_frame()
,
layer_neatline()
,
layer_scaled()
Use mapboxapi to make a Mapbox static map layer
layer_mapbox( data = NULL, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style_url = "mapbox://styles/mapbox/satellite-streets-v11", style_id = NULL, username = NULL, basemap = FALSE, scale = 0.75, scaling_factor = "1x", attribution = TRUE, logo = TRUE, access_token = NULL, neatline = TRUE, color = "black", bgcolor = "white", linewidth = 0.5, linetype = "solid", expand = TRUE, hide_grid = TRUE, label_axes = "----", ... )
layer_mapbox( data = NULL, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style_url = "mapbox://styles/mapbox/satellite-streets-v11", style_id = NULL, username = NULL, basemap = FALSE, scale = 0.75, scaling_factor = "1x", attribution = TRUE, logo = TRUE, access_token = NULL, neatline = TRUE, color = "black", bgcolor = "white", linewidth = 0.5, linetype = "solid", expand = TRUE, hide_grid = TRUE, label_axes = "----", ... )
data |
A |
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 |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; 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, |
style_url |
Map style url used to fill style_id and username parameters, Default: "mapbox://styles/mapbox/satellite-streets-v11" |
style_id |
A style ID (required if style_url is |
username |
A Mapbox username (required if |
basemap |
If FALSE, create a standalone layer; if |
scale |
ratio to scale the output image; |
scaling_factor |
The scaling factor of the tiles; either |
attribution |
Controls whether there is attribution on the image.
Defaults to |
logo |
Controls whether there is a Mapbox logo on the image. Defaults to
|
access_token |
A Mapbox access token; which can be set with mb_access_token. |
neatline |
If |
color |
Color of panel border, Default: 'black' |
bgcolor |
Fill color of panel background; defaults to "white". If
"none", panel background is set to |
linewidth |
Line width of panel border, Default: 0.5 |
linetype |
Line type of panel border, Default: 'solid' |
expand |
If |
hide_grid |
If |
label_axes |
A description of which axes to label passed to
|
... |
Additional parameter passed to mapboxapi::layer_static_mapbox |
mapboxapi::layer_static_mapbox()
Use ggforce::geom_mark_rect()
, ggforce::geom_mark_circle()
,
ggforce::geom_mark_ellipse()
, or ggforce::geom_mark_hull()
to annotate
simple feature objects. This function modifies the geometry and sets the stat
to "st_coordinates" to make it easy to use these annotation geoms with simple
feature objects.
layer_marked( data, fn = NULL, mapping = NULL, label_col = NULL, desc_col = NULL, geom = NULL, center = FALSE, font_family = NULL, font_face = c("bold", "plain"), font_color = NULL, expand = ggplot2::unit(5, "mm"), radius = expand, stat = "sf_coordinates", drop_shadow = FALSE, shadow_params = list(x_offset = 5, y_offset = 5, sigma = 0.5, ...), ... )
layer_marked( data, fn = NULL, mapping = NULL, label_col = NULL, desc_col = NULL, geom = NULL, center = FALSE, font_family = NULL, font_face = c("bold", "plain"), font_color = NULL, expand = ggplot2::unit(5, "mm"), radius = expand, stat = "sf_coordinates", drop_shadow = FALSE, shadow_params = list(x_offset = 5, y_offset = 5, sigma = 0.5, ...), ... )
data |
A |
fn |
Function to apply to data before passing to geom, typically a predicate or filter to define area for annotation. A filter can also be passed to any of the {ggforce} functions using the filter aesthetic. Default: NULL |
mapping |
Aesthetic mapping to pass to geom, Default: |
label_col |
Label column name |
desc_col |
Column name to use for description. Defaults to |
geom |
geom to use for layer (options include "rect", "circle",
"ellipse", or "hull"), Default: |
center |
If |
font_family , font_face , font_color
|
Parameters passed to label.family,
label.fontface, and label.colour. If |
expand |
A numeric or unit vector of length one, specifying the expansion amount. Negative values will result in contraction instead. If the value is given as a numeric it will be understood as a proportion of the plot area width. |
radius |
As |
stat |
stat to pass to ggforce function; defaults to "sf_coordinates" |
drop_shadow |
If |
shadow_params |
Parameters passed to |
... |
Additional parameters passed to |
If cast is FALSE
and the data geometry type is MULTIPOLYGON or POLYGON, the
annotation uses a centroid for the annotation geometry. If cast is TRUE
,
the data is converted to POINT geometry using sfext::st_cast_ext()
and the
modified geometry passed on to selected geom.
Labels and descriptions can be included in the aesthetic mapping for the layer consistent with the standard documented approaches for all four functions.
Labels and descriptions also can be set in two non-standard ways:
Setting label_col and/or or desc_col to character strings with the column names for labels and/or descriptions
Setting label_col and/or desc_col with the value of the label/description
If the first approach is used, label_col and desc_col can also can be created or modified by a function provided to the fn parameter. Otherwise, the columns must be present in the data to work. If the second approach is used, the length and order of vector provided to label_col and/or desc_col must match that length and order of the data (after the fn is applied).
## Not run: if (interactive()) { # Mark the 12th Council District on a Baltimore neighborhood basemap ggplot::ggplot() + layer_location_data( data = "neighborhoods", package = "mapbaltimore" ) + layer_marked( data = getdata::get_location( type = "council district", name = "District 12", package = "mapbaltimore" ), geom = "hull", color = "red", size = 1.5 ) } ## End(Not run)
## Not run: if (interactive()) { # Mark the 12th Council District on a Baltimore neighborhood basemap ggplot::ggplot() + layer_location_data( data = "neighborhoods", package = "mapbaltimore" ) + layer_marked( data = getdata::get_location( type = "council district", name = "District 12", package = "mapbaltimore" ), geom = "hull", color = "red", size = 1.5 ) } ## End(Not run)
If make is TRUE
, groupname_col, group_meta, crs, and fn is all passed on to
make_markers.
layer_markers( data, mapping = NULL, geom = "sf", make = FALSE, groupname_col = NULL, group_meta = NULL, crs = getOption("maplayer.crs", default = 3857), number = FALSE, num_by_group = FALSE, num_style = NULL, num_start = 1, suffix = NULL, sort = "dist_xmin_ymax", desc = FALSE, fn = NULL, ... ) layer_numbers( data, mapping = NULL, geom = "label", make = FALSE, groupname_col = NULL, style = "roundrect", size = 5, sort = "dist_xmin_ymax", num_by_group = FALSE, num_style = NULL, num_start = 1, suffix = NULL, desc = FALSE, fn = NULL, crs = getOption("maplayer.crs", default = 3857), label.size = 0, label.padding = ggplot2::unit(size/10, "lines"), label.r = label.padding * 1.5, hjust = 0.5, vjust = 0.5, ... ) make_markers( data, groupname_col = NULL, group_meta = NULL, join = sf::st_intersects, geo = FALSE, coords = c("lon", "lat"), address = "address", point = TRUE, crs = NULL, fn = NULL, ... )
layer_markers( data, mapping = NULL, geom = "sf", make = FALSE, groupname_col = NULL, group_meta = NULL, crs = getOption("maplayer.crs", default = 3857), number = FALSE, num_by_group = FALSE, num_style = NULL, num_start = 1, suffix = NULL, sort = "dist_xmin_ymax", desc = FALSE, fn = NULL, ... ) layer_numbers( data, mapping = NULL, geom = "label", make = FALSE, groupname_col = NULL, style = "roundrect", size = 5, sort = "dist_xmin_ymax", num_by_group = FALSE, num_style = NULL, num_start = 1, suffix = NULL, desc = FALSE, fn = NULL, crs = getOption("maplayer.crs", default = 3857), label.size = 0, label.padding = ggplot2::unit(size/10, "lines"), label.r = label.padding * 1.5, hjust = 0.5, vjust = 0.5, ... ) make_markers( data, groupname_col = NULL, group_meta = NULL, join = sf::st_intersects, geo = FALSE, coords = c("lon", "lat"), address = "address", point = TRUE, crs = NULL, fn = NULL, ... )
data |
Character string (e.g. url, file path, or name of data from
package) for a spatial data or a |
mapping |
Set of aesthetic mappings created by |
geom |
A character string indicating which ggplot2 geom to use, Default:
'sf'. Options include "sf" ( |
make |
If |
groupname_col |
Group column name, used to join group metadata if
group_meta is a non-spatial data frame; Default: |
group_meta |
Group metadata as a data frame or sf object that intersect
with markers (using join function); Default: |
crs |
Coordinate reference system for markers, Default: |
number |
If |
num_by_group |
If |
num_style |
Style of enumeration, either "arabic", "alph", "Alph", "roman", "Roman". |
num_start |
Starting number; defaults to 1. |
suffix |
Character to appended to "number" column. (e.g. "." for "1." or ":" for "1:"). Can also be a character vector with the same length as the number column. |
sort |
Sort column name, Default: "dist_xmin_ymax". |
desc |
If |
fn |
Function to apply to data before results; gives warning if data is
grouped; Default: |
... |
Additional parameters passed to |
style |
Marker style; defaults to |
size |
Marker size, Default: 5 |
label.size |
Size of label border, in mm. |
label.padding |
Amount of padding around label. Defaults to 0.25 lines. |
label.r |
Radius of rounded corners. Defaults to 0.15 lines. |
hjust , vjust
|
Horizontal and vertical justification. |
join |
Spatial relation function to combine data with group_meta, passed
to |
geo |
If |
coords |
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat"). |
address |
Address column name passed to |
point |
If |
ggplot2 layers
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, 3857) basemap <- ggplot() + layer_location_data( data = nc, fill = NA ) basemap + layer_markers( data = nc[1:10], mapping = aes(size = AREA), make = TRUE ) large_nc <- getdata::get_location_data( data = nc, fn = ~ dplyr::filter(.x, AREA > 0.2) ) large_nc$number <- 1 large_nc$dist <- 2 basemap + layer_numbers( data = large_nc, mapping = aes(fill = NAME), sort = "dist_xmax_ymin", num_style = "Roman", geom = "label", size = 3 ) + guides(fill = "none")
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, 3857) basemap <- ggplot() + layer_location_data( data = nc, fill = NA ) basemap + layer_markers( data = nc[1:10], mapping = aes(size = AREA), make = TRUE ) large_nc <- getdata::get_location_data( data = nc, fn = ~ dplyr::filter(.x, AREA > 0.2) ) large_nc$number <- 1 large_nc$dist <- 2 basemap + layer_numbers( data = large_nc, mapping = aes(fill = NAME), sort = "dist_xmax_ymin", num_style = "Roman", geom = "label", size = 3 ) + guides(fill = "none")
Returns a mask for an area or areas as a simple feature object. neatline = TRUE
only works for this layer if data is passed directly; not inherited.
layer_mask( data = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, crs = getOption("maplayer.crs", default = 3857), fill = "white", color = NA, alpha = 0.5, mask = NULL, neatline = FALSE, expand = TRUE, ... ) set_mask(x = NULL, mask = TRUE, data = NULL, crs = NULL, ...)
layer_mask( data = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, crs = getOption("maplayer.crs", default = 3857), fill = "white", color = NA, alpha = 0.5, mask = NULL, neatline = FALSE, expand = TRUE, ... ) set_mask(x = NULL, mask = TRUE, data = NULL, crs = NULL, ...)
data |
|
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 |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; 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, |
crs |
Coordinate reference system of bounding box to return; defaults to
|
fill |
mask fill color; defaults to "white" |
color |
mask edge color; defaults to |
alpha |
mask alpha/transparency; defaults to 0.5 |
mask |
A |
neatline |
A logical object,
|
expand |
If |
... |
Additional parameters to pass to |
x |
A |
ggplot2::geom_sf()
function.
Set limits for a map to the bounding box of a feature using
ggplot2::coord_sf()
. Optionally, adjust the x size by applying a buffer
and/or adjust the aspect ratio of the limiting bounding box to match a set
aspect ratio.
layer_neatline( data = NULL, dist = getOption("maplayer.dist"), diag_ratio = getOption("maplayer.diag_ratio"), unit = getOption("maplayer.unit", default = "meter"), asp = getOption("maplayer.asp"), crs = getOption("maplayer.crs"), nudge = getOption("maplayer.nudge"), color = "black", linewidth = 0.5, linetype = "solid", bgcolor = "white", expand = TRUE, hide_grid = TRUE, label_axes = "----", axis.title = NULL, axis.text = NULL, axis.ticks = NULL, axis.ticks.length = ggplot2::unit(x = 0, units = "mm"), axis.line = NULL, panel.grid = NULL, panel.grid.major = NULL, panel.grid.minor = NULL, panel.border = NULL, panel.background = NULL, plot.background = NULL, plot.margin = NULL, default_plot_margin = ggplot2::margin(1, 1, 1, 1), xlim = NULL, ylim = NULL, ... ) theme_grid( hide_grid = TRUE, grid = FALSE, panel.grid = NULL, panel.grid.major = NULL, panel.grid.minor = NULL ) theme_sf_axis( label_axes = "----", axis.title = NULL, axis.text = NULL, axis.text.x = NULL, axis.text.y = NULL, axis.ticks = NULL, axis.ticks.length = ggplot2::unit(x = 0, units = "mm"), axis.line = NULL, ... ) set_neatline(x = NULL, neatline = TRUE, data = NULL, crs = NULL, ...)
layer_neatline( data = NULL, dist = getOption("maplayer.dist"), diag_ratio = getOption("maplayer.diag_ratio"), unit = getOption("maplayer.unit", default = "meter"), asp = getOption("maplayer.asp"), crs = getOption("maplayer.crs"), nudge = getOption("maplayer.nudge"), color = "black", linewidth = 0.5, linetype = "solid", bgcolor = "white", expand = TRUE, hide_grid = TRUE, label_axes = "----", axis.title = NULL, axis.text = NULL, axis.ticks = NULL, axis.ticks.length = ggplot2::unit(x = 0, units = "mm"), axis.line = NULL, panel.grid = NULL, panel.grid.major = NULL, panel.grid.minor = NULL, panel.border = NULL, panel.background = NULL, plot.background = NULL, plot.margin = NULL, default_plot_margin = ggplot2::margin(1, 1, 1, 1), xlim = NULL, ylim = NULL, ... ) theme_grid( hide_grid = TRUE, grid = FALSE, panel.grid = NULL, panel.grid.major = NULL, panel.grid.minor = NULL ) theme_sf_axis( label_axes = "----", axis.title = NULL, axis.text = NULL, axis.text.x = NULL, axis.text.y = NULL, axis.ticks = NULL, axis.ticks.length = ggplot2::unit(x = 0, units = "mm"), axis.line = NULL, ... ) set_neatline(x = NULL, neatline = TRUE, data = NULL, crs = NULL, ...)
data |
A |
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 |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; 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, |
crs |
The coordinate reference system (CRS) into which all data should be projected before plotting. If not specified, will use the CRS defined in the first sf layer of the plot. |
nudge |
Passed as to parameter |
color |
Color of panel border, Default: 'black' |
linewidth |
Line width of panel border, Default: 0.5 |
linetype |
Line type of panel border, Default: 'solid' |
bgcolor |
Fill color of panel background; defaults to "white". If
"none", panel background is set to |
expand |
If |
hide_grid |
If |
label_axes |
A description of which axes to label passed to
|
axis.title , axis.text , axis.ticks , axis.ticks.length , axis.line
|
Theme elements passed as is if label_axes is anything other than "—-". |
panel.grid , panel.grid.major , panel.grid.minor
|
Passed as is if hide_grid is FALSE. |
panel.border , panel.background , plot.background , plot.margin
|
panel.border
is used as is if not NULL or |
default_plot_margin |
Defaults to |
xlim , ylim
|
Limits for the x and y axes. These limits are specified
in the units of the default CRS. By default, this means projected coordinates
( |
... |
Additional parameters passed to |
grid |
If |
axis.text.x , axis.text.y
|
Passed to |
x |
For |
neatline |
A logical object,
|
List of ggplot2::coord_sf and ggplot2::theme calls.
Other layer:
layer_frame()
,
layer_location_data()
,
layer_scaled()
library(ggplot2) nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) ggplot() + layer_location_data(data = nc) + layer_neatline(data = nc[1, ], asp = 1, color = "red", linewidth = 1, linetype = "dashed") ggplot() + layer_location_data(data = nc) + layer_neatline(data = nc[1, ], dist = 20, unit = "mi", color = "none")
library(ggplot2) nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) ggplot() + layer_location_data(data = nc) + layer_neatline(data = nc[1, ], asp = 1, color = "red", linewidth = 1, linetype = "dashed") ggplot() + layer_location_data(data = nc) + layer_neatline(data = nc[1, ], dist = 20, unit = "mi", color = "none")
Use ggrepel::geom_label_repel or ggrepel::geom_text_repel with
ggplot2::stat_sf_coordinates()
to create a layer of textual annotations
repelled from simple feature locations.
layer_repel( mapping = aes(), data = NULL, label_col = "name", geom = c("text", "label"), location_lims = NULL, xlim = c(NA, NA), ylim = c(NA, NA), ... ) geom_sf_label_repel(mapping = aes(), data = NULL, label_col = "name", ...) geom_sf_text_repel(mapping = aes(), data = NULL, label_col = "name", ...)
layer_repel( mapping = aes(), data = NULL, label_col = "name", geom = c("text", "label"), location_lims = NULL, xlim = c(NA, NA), ylim = c(NA, NA), ... ) geom_sf_label_repel(mapping = aes(), data = NULL, label_col = "name", ...) geom_sf_text_repel(mapping = aes(), data = NULL, label_col = "name", ...)
mapping |
Set of aesthetic mappings created by |
data |
A data frame. If specified, overrides the default data frame defined at the top level of the plot. |
label_col |
Column name to use for label aesthetic mapping. Optional if label is provided to mapping; required otherwise. |
geom |
Character vector with geom to use, "text" for
|
location_lims |
A |
xlim , ylim
|
Limits for the x and y axes. Text labels will be constrained to these limits. By default, text labels are constrained to the entire plot area. |
... |
Arguments passed on to
|
Uses layer_neatline, sfext::standard_scales, and sfext::convert_dist_scale.
layer_scaled( data = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, crs = getOption("maplayer.crs", default = 3857), scale = NULL, paper = NULL, orientation = NULL, clip = FALSE )
layer_scaled( data = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, crs = getOption("maplayer.crs", default = 3857), scale = NULL, paper = NULL, orientation = NULL, clip = FALSE )
data |
A |
dist |
distance to convert. If paper is provided, dist is optional and paper width and height are used as dist. |
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 |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; 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, |
crs |
Coordinate reference system of bounding box to return; defaults to
|
scale |
Scale name from |
paper |
Paper, Default: 'letter'. |
orientation |
Orientation "portrait", "landscape", or "square", Default: 'portrait'. |
clip |
If |
Other layer:
layer_frame()
,
layer_location_data()
,
layer_neatline()
layer_location_data()
Location is used as the data parameter of layer_location_data so this
function is primarily appropriate for the layer_mapbox (geom = "mapbox"
).
make_location_map( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, data = NULL, crs = NULL, paper = NULL, width = NULL, height = NULL, units = "in", orientation = NULL, geom = "sf", basemap = TRUE, bg_layer = NULL, layer = NULL, fg_layer = NULL, addon = NULL, neatline = FALSE, labs_ext_params = list(...), save = FALSE, ggsave_params = list(dpi = 300, ...), ..., env = caller_env(), call = caller_env() ) make_social_map( location, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, crs = 3857, image = NULL, platform = NULL, format = NULL, orientation = NULL, basemap = TRUE, geom = "mapbox", save = FALSE, ggsave_params = list(fileext = "jpeg", dpi = 72, ...), ... ) make_image_map( image_path, location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, data = NULL, crs = 3857, paper = "Letter", orientation = NULL, geom = "mapbox", style_url = NULL, basemap = TRUE, bg_layer = NULL, fg_layer = NULL, save = FALSE, ggsave_params = list(dpi = 300, ...), image_geom = "label", groupname_col = NULL, group_meta = NULL, number = FALSE, num_by_group = FALSE, num_style = NULL, num_start = 1, suffix = NULL, sort = "dist_xmin_ymax", desc = FALSE, ... ) make_layer_map( bg_layer = NULL, layer = NULL, fg_layer = NULL, addon = NULL, basemap = NULL, neatline = NULL, labs_ext_params = NULL, save = FALSE, ggsave_params = list(width = 5, height = 4, unit = "in", dpi = 300), env = caller_env(), call = caller_env() )
make_location_map( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, data = NULL, crs = NULL, paper = NULL, width = NULL, height = NULL, units = "in", orientation = NULL, geom = "sf", basemap = TRUE, bg_layer = NULL, layer = NULL, fg_layer = NULL, addon = NULL, neatline = FALSE, labs_ext_params = list(...), save = FALSE, ggsave_params = list(dpi = 300, ...), ..., env = caller_env(), call = caller_env() ) make_social_map( location, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, crs = 3857, image = NULL, platform = NULL, format = NULL, orientation = NULL, basemap = TRUE, geom = "mapbox", save = FALSE, ggsave_params = list(fileext = "jpeg", dpi = 72, ...), ... ) make_image_map( image_path, location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, data = NULL, crs = 3857, paper = "Letter", orientation = NULL, geom = "mapbox", style_url = NULL, basemap = TRUE, bg_layer = NULL, fg_layer = NULL, save = FALSE, ggsave_params = list(dpi = 300, ...), image_geom = "label", groupname_col = NULL, group_meta = NULL, number = FALSE, num_by_group = FALSE, num_style = NULL, num_start = 1, suffix = NULL, sort = "dist_xmin_ymax", desc = FALSE, ... ) make_layer_map( bg_layer = NULL, layer = NULL, fg_layer = NULL, addon = NULL, basemap = NULL, neatline = NULL, labs_ext_params = NULL, save = FALSE, ggsave_params = list(width = 5, height = 4, unit = "in", dpi = 300), env = caller_env(), call = caller_env() )
location |
A sf object passed to |
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 |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; 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, |
data |
Character string (e.g. url, file path, or name of data from
package) for a spatial data or a |
crs |
Coordinate reference system of bounding box to return; defaults to
|
paper |
Paper matching name from |
width |
Page width in "in", "px" or "mm" units. Default: |
height |
Page height in "in", "px" or "mm" units. Default: |
units |
Units to convert page dimensions to using |
orientation |
Page orientation, Default: |
geom |
A character string indicating which ggplot2 geom to use, Default:
'sf'. Options include "sf" ( |
basemap |
Either a logical vector or ggplot object. If logical and If a ggplot, add x to basemap object. If a ggproto object (or list that contains a ggproto object), add x
and basemap object to |
bg_layer , fg_layer , addon
|
A ggplot2 layer or a list of ggproto objects
(e.g. scales, labels, etc.) to add to the background or foreground of the
primary map layer defined by |
layer |
A ggplot2 layer or a list of ggproto objects. If layer is
provided, all parameters passed to |
neatline |
A logical object,
|
labs_ext_params |
Optional parameters passed to |
save |
If |
ggsave_params |
List of parameters passed to |
... |
Additional parameters passed to |
env |
Environment for evaluation of |
call |
The execution environment of a currently
running function, e.g. |
image |
Image name passed to name parameter of |
platform |
Social media platform, "Instagram", "Facebook", or "Twitter",
Default: |
format |
Image format, "post", "story", or "cover", Default: |
image_path |
path to location of images for |
style_url |
A Mapbox style url; defaults to |
image_geom |
For |
groupname_col |
Group column name, used to join group metadata if
group_meta is a non-spatial data frame; Default: |
group_meta |
Group metadata as a data frame or sf object that intersect
with markers (using join function); Default: |
number |
If |
num_by_group |
If |
num_style |
Style of enumeration, either "arabic", "alph", "Alph", "roman", "Roman". |
num_start |
Starting number; defaults to 1. |
suffix |
Character to appended to "number" column. (e.g. "." for "1." or ":" for "1:"). Can also be a character vector with the same length as the number column. |
sort |
Sort column name, Default: "dist_xmin_ymax". |
desc |
If |
Using make_image_map()
:
make_image_map()
wraps sfext::read_sf_exif()
and make_location_map()
.
It is designed for making simple maps of photos in combination with reference
tables.
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) make_location_map( location = nc ) name <- "North Carolina" make_location_map( location = nc, labs_ext_params = list( title = "Map of {name}" ) ) make_location_map( data = nc, location = nc[2, ], dist = 2, unit = "mi", crop = FALSE, addon = ggplot2::theme_minimal(), labs_ext_params = list( title = "Map of {nc[2, ]$NAME} County" ) ) make_location_map( basemap = ggplot(data = nc[2,]), fg_layer = geom_sf_text(aes(label = NAME)), data = nc, location = nc[2, ], mapping = aes(fill = NAME), addon = guides(fill = "none"), dist = 2, unit = "mi", crop = FALSE, neatline = TRUE, labs_ext_params = list( title = "Map of {nc[2, ]$NAME} and surrounding {name} counties" ) )
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) make_location_map( location = nc ) name <- "North Carolina" make_location_map( location = nc, labs_ext_params = list( title = "Map of {name}" ) ) make_location_map( data = nc, location = nc[2, ], dist = 2, unit = "mi", crop = FALSE, addon = ggplot2::theme_minimal(), labs_ext_params = list( title = "Map of {nc[2, ]$NAME} County" ) ) make_location_map( basemap = ggplot(data = nc[2,]), fg_layer = geom_sf_text(aes(label = NAME)), data = nc, location = nc[2, ], mapping = aes(fill = NAME), addon = guides(fill = "none"), dist = 2, unit = "mi", crop = FALSE, neatline = TRUE, labs_ext_params = list( title = "Map of {nc[2, ]$NAME} and surrounding {name} counties" ) )
Wraps make_layer_map()
and passes layer created with layer_mapbox()
to
basemap and the neatline parameters to layer_neatline()
(using the same
data as the Mapbox background layer). The neatline parameters are only used
if neatline is NULL
.
make_mapbox_map( data = NULL, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style_url = "mapbox://styles/mapbox/satellite-streets-v11", style_id = NULL, username = NULL, basemap = TRUE, scale = 0.75, scaling_factor = "1x", attribution = TRUE, logo = TRUE, access_token = NULL, neatline = NULL, color = "black", bgcolor = "white", linewidth = 0.5, linetype = "solid", expand = TRUE, hide_grid = TRUE, label_axes = "----", width = NULL, height = NULL, units = NULL, orientation = NULL, location = NULL, ... )
make_mapbox_map( data = NULL, dist = NULL, diag_ratio = NULL, unit = "meter", asp = NULL, style_url = "mapbox://styles/mapbox/satellite-streets-v11", style_id = NULL, username = NULL, basemap = TRUE, scale = 0.75, scaling_factor = "1x", attribution = TRUE, logo = TRUE, access_token = NULL, neatline = NULL, color = "black", bgcolor = "white", linewidth = 0.5, linetype = "solid", expand = TRUE, hide_grid = TRUE, label_axes = "----", width = NULL, height = NULL, units = NULL, orientation = NULL, location = NULL, ... )
data |
A |
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 |
unit |
Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; 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, |
style_url |
Map style url used to fill style_id and username parameters, Default: "mapbox://styles/mapbox/satellite-streets-v11" |
style_id |
A style ID (required if style_url is |
username |
A Mapbox username (required if |
basemap |
If FALSE, create a standalone layer; if |
scale |
ratio to scale the output image; |
scaling_factor |
The scaling factor of the tiles; either |
attribution |
Controls whether there is attribution on the image.
Defaults to |
logo |
Controls whether there is a Mapbox logo on the image. Defaults to
|
access_token |
A Mapbox access token; which can be set with mb_access_token. |
neatline |
If |
color |
Color of panel border, Default: 'black' |
bgcolor |
Fill color of panel background; defaults to "white". If
"none", panel background is set to |
linewidth |
Line width of panel border, Default: 0.5 |
linetype |
Line type of panel border, Default: 'solid' |
expand |
If |
hide_grid |
If |
label_axes |
A description of which axes to label passed to
|
width , height
|
Page width and height. Both are required, if asp is
|
units |
Units for width and height. Required unless units is included in
dims. Passed to |
orientation |
Page orientation, Default: |
location |
If |
... |
Arguments passed on to
|
An index of map icons from seven sources:
Most of these icon sources use open licenses. Maki, Temaki, and the OSM lane icons all use a CC0 license. The Weather Underground Icons use an MIT license. The OSM map icons use an unspecified PD style license. The Calcite icons are available under the Esri Master License Agreement (MLA). The NPMap Symbol Library is created by the National Park Service so is assumed to be a Public Domain work in the U.S..
This index was last updated on 2024-04-08 and may not include any icons that have been added since that date.
map_icons
map_icons
A tibble with 5,036 rows and 5 variables:
name
Icon name
url
Icon URL on GitHub repo
style
Icon style (blank if not applicable)
size
Icon width/height (pixels)
repo
GitHub repository for icon collection
The name column is not unique so a px or source may be required when using
layer_icon()
.
Designed for use with layer_group_data. group_data_pal generates palettes that are passed to ggplot2::scale_fill_manual and ggplot2::scale_color_manual.
scale_group_data( ..., data, col = NULL, palette = NULL, n = NULL, direction = 1, na.value = "grey50", drop = FALSE, limits = NULL, aesthetics = "fill" ) group_data_pal( data, palette = NULL, col = NULL, n = NULL, direction = 1, pkg = NULL ) get_group_data_pal_scale(data, col = NULL, palette = NULL, ...)
scale_group_data( ..., data, col = NULL, palette = NULL, n = NULL, direction = 1, na.value = "grey50", drop = FALSE, limits = NULL, aesthetics = "fill" ) group_data_pal( data, palette = NULL, col = NULL, n = NULL, direction = 1, pkg = NULL ) get_group_data_pal_scale(data, col = NULL, palette = NULL, ...)
... |
Arguments passed on to
|
data |
Data to use when generating scale or palette. |
col |
Grouping column found in data to use in generating scale or
palette; defaults to |
palette |
Name of palette as a string. Must be on the form packagename::palettename. |
n |
Number of colors desired. If omitted, returns complete palette. |
direction |
Either |
na.value |
The aesthetic value to use for missing ( |
drop |
Should unused factor levels be omitted from the scale?
The default, |
limits |
One of:
|
aesthetics |
Character string or vector of character strings listing the
name(s) of the aesthetic(s) that this scale works with. This can be useful, for
example, to apply colour settings to the |
pkg |
Package name to use as prefix for palette name when selecting a
palette with |
scales::viridis_pal()
paletteer::paletteer_d()
Add a basemap to a ggplot2 layer.
set_basemap(x, basemap = FALSE, call = caller_env()) make_basemap(x, basemap = FALSE, call = caller_env())
set_basemap(x, basemap = FALSE, call = caller_env()) make_basemap(x, basemap = FALSE, call = caller_env())
x |
A ggproto object or list of ggproto objects. |
basemap |
Either a logical vector or ggplot object. If logical and If a ggplot, add x to basemap object. If a ggproto object (or list that contains a ggproto object), add x
and basemap object to |
call |
The execution environment of a currently
running function, e.g. |
Helper functions for modifying a ggplot theme. The "replace" and "update" options for the method parameter are not currently working; keeping method = NULL or method = "set" is recommended.
theme_text( font_family = NULL, color = "black", geom_text = TRUE, hjust = NULL, vjust = NULL, method = NULL, ... ) theme_margin( margin = "standard", paper = NULL, orientation = NULL, dist = NULL, unit = "in", block_width = NULL, header = 0, footer = 0, fill = NA, color = NA, linewidth = 0, size = NULL, method = NULL, ... ) theme_legend( position = NULL, justification = NULL, margin = 8, unit = "pt", inset = TRUE, nudge_inset = 0.05, bgcolor = "white", title = list(face = "bold", align = 0), method = NULL, ... )
theme_text( font_family = NULL, color = "black", geom_text = TRUE, hjust = NULL, vjust = NULL, method = NULL, ... ) theme_margin( margin = "standard", paper = NULL, orientation = NULL, dist = NULL, unit = "in", block_width = NULL, header = 0, footer = 0, fill = NA, color = NA, linewidth = 0, size = NULL, method = NULL, ... ) theme_legend( position = NULL, justification = NULL, margin = 8, unit = "pt", inset = TRUE, nudge_inset = 0.05, bgcolor = "white", title = list(face = "bold", align = 0), method = NULL, ... )
font_family |
Font family, Default: 'Helvetica' If |
color |
Color for text elements (passed to
|
geom_text |
If |
hjust , vjust
|
Horizontal and vertical justification. |
method |
Method with name of the ggplot2 geom function to use for
modifying theme ("set", "update", or "replace"); defaults to |
... |
Additional parameters passed to |
margin |
Margin distance, a margin style supported by |
paper |
Paper, Default: 'letter'. |
orientation |
Page orientation, Default: |
dist |
Margin distance (single value used to all sides), Default: |
unit |
Legend margin units; defaults to 'pt'. |
block_width |
Plot or map width in units. If |
header , footer
|
Header and footer height in units; defaults to 0. Please note: headers and footers are not currently supported for "px" units. |
fill |
Fill for |
linewidth , size
|
Passed to linewidth of |
position |
Legend position (“left”,“top”, “right”, “bottom”) or a two-element numeric vector to set position using Normalized Parent Coordinates ("npc"); defaults NULL |
justification |
If |
inset |
If |
nudge_inset |
Position adjustment in "npc" units to use for inset legends. Defaults to 0.05. |
bgcolor |
Fill color for legend background; defaults to 'white'. |
title |
Attributes to use for legend.title text (e.g. face and align). |