Static ggplot2 maps or interactive leaflet maps. Colour points by any
column, or leave them uncoloured (color = "none", the default).
basemap = "outline" adds province / region linework.
Arguments
- data
An
obs_dffromobs_read(), a data frame withlat/lng, or a path to an export.- type
"static"(ggplot2) or"interactive"(leaflet).- color
Column used to colour points, or
"none"(default) for a single colour. Typical values:c("none", "scientific_name", "common_name", "sex", "species_group", "life_stage", "activity", "validation"). Any other column indataalso works.- size_by
Optional column for point size.
- use_obs_colors
If
TRUEandcoloris"validation"or"sex", use the official Observation.org / sex palettes. Ignored whenpaletteis set. IfFALSE, a ColorBrewer, viridis or HCL palette is used instead (numeric columns get a continuous gradient).- palette
Optional colours for
color. A named vector (c("Male" = "#2E86AB", "Female" = "#D34242")), an unnamed vector recycled over the unique values, or a functionfunction(n)that returnsncolours. Overridesuse_obs_colors. Ignored whencolor = "none".- max_points
Maximum points to plot.
- title
Map title.
- show_legend
If
TRUE, show the legend.- basemap
For static maps:
"none"(default),"outline"(province / region linework for context), or"naturalearth"(filled countries)."outline"uses Eurostat GISCO NUTS 3 in Europe (finer, province-level) and Natural Earth admin-1 worldwide (states / regions / provinces). Both are cached after the first download. Ignored for interactive maps, which use OpenStreetMap (default) and a satellite layer.- basemap_zoom
Zoom for the Natural Earth basemap (
NULL= automatic).- polygon
Optional area to draw (and, when
datais a file path, to filter). WKT, GeoJSON, a path, orsf. Requires sf.- ...
Passed to
obs_read()whendatais a file path.
Details
polygon draws a WKT, GeoJSON or sf boundary. When data is a file
path, the same polygon is passed to obs_read() and also filters the
points. See vignette("spatial-filters").
Interactive maps use OpenStreetMap by default (plus a satellite layer). All points are drawn in one leaflet layer. From 1,000 points they are clustered so the browser stays responsive; zoom in to split a cluster. Clicking a marker opens a popup with every non-empty field.
Examples
if (FALSE) { # \dontrun{
obs <- obs_read(obs_example_db(), species = "Passer domesticus")
obs_map(obs)
obs_map(obs, color = "scientific_name", basemap = "outline")
obs_map(
obs,
color = "sex",
palette = c(
Male = "#2E86AB", Female = "#D34242", Unspecified = "#999999"
)
)
obs_map(obs, polygon = "POLYGON ((-6.1 37.3, -5.8 37.3, -5.8 37.5, -6.1 37.5, -6.1 37.3))")
} # }