
Return a static Mapbox map from a specified style
Prepare overlay markers for use in a Mapbox static map
static_mapbox(
style_id,
username,
overlay_sf = NULL,
overlay_style = NULL,
overlay_markers = NULL,
longitude = NULL,
latitude = NULL,
zoom = NULL,
width = 600,
height = 400,
bearing = NULL,
pitch = NULL,
scaling_factor = c("1x", "2x"),
before_layer = NULL,
access_token = NULL
)prep_overlay_markers(
data = NULL,
marker_type = c("pin-s", "pin-l", "url"),
label = NA,
color = NA,
longitude = NULL,
latitude = NULL,
url = NA
)
The style ID
Your Mapbox username
The overlay sf object (optional). The function will convert the sf object to GeoJSON then plot over the basemap style. Spatial data that are too large will trigger an error, and should be added to the style in Mapbox Studio instead.
A named list of vectors pecifying how to style the sf overlay. Possible names are "stroke", "stroke-width", "stroke-opacity", "fill", and "fill-opacity". The fill and stroke color values should be specified as six-digit hex codes, and the opacity and width values should be supplied as floating-point numbers.
The prepared overlay markers (optional). See the function prep_overlay_markers
for more information on how to specify a marker overlay.
A vector of longitudes; inferred from the input dataset if data
is provided.
A vector of latitudes; inferred from the input dataset if data
is provided.
The map zoom. The map will infer this from the overlay unless longitude, latitude, and zoom are all specified.
The map width; defaults to 600px
The map height; defaults to 600px
The map bearing; defaults to 0
The map pitch; defaults to 0
The scaling factor of the tiles; either "1x"
(the default) or "2x"
A character string that specifies where in the hierarchy of layer elements the overlay should be inserted. The overlay will be placed just above the specified layer in the given Mapbox styles.
Your Mapbox access token; can be set with mb_access_token()
.
An input data frame with longitude and latitude columns (X and Y or lon and lat as names are also acceptable) or an sf object with geometry type POINT.
The marker type; one of "pin-s"
, for a small pin; "pin-l"
, for a large pin; and "url"
, for an image path.
The marker label (optional). Can be a letter, number (0 through 99), or a valid Maki icon (see https://labs.mapbox.com/maki-icons/) for options).
The marker color (optional). Color should be specified as a three or six-digit hexadecimal code without the number sign.
The URL of the image to be used for the icon if marker_type = "url"
.
A pointer to an image of class "magick-image"
. The resulting image can be manipulated further with functions from the magick package.
A formatted list of marker specifications that can be passed to the static_mapbox
function.
# NOT RUN {
library(mapboxapi)
points_of_interest <- tibble::tibble(
longitude = c(-73.99405, -74.00616, -73.99577, -74.00761),
latitude = c(40.72033, 40.72182, 40.71590, 40.71428)
)
prepped_pois <- prep_overlay_markers(
data = points_of_interest,
marker_type = "pin-l",
label = 1:4,
color = "fff"
)
map <- static_mapbox(
style_id = "streets-v11",
username = "mapbox",
overlay_markers = prepped_pois,
width = 1200,
height = 800
)
map
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab