Skip to contents

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.

Usage

obs_map(
  data,
  type = c("static", "interactive"),
  color = "none",
  size_by = NULL,
  use_obs_colors = TRUE,
  palette = NULL,
  max_points = 10000,
  title = NULL,
  show_legend = TRUE,
  basemap = c("none", "outline", "naturalearth"),
  basemap_zoom = NULL,
  polygon = NULL,
  ...
)

Arguments

data

An obs_df from obs_read(), a data frame with lat/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 in data also works.

size_by

Optional column for point size.

use_obs_colors

If TRUE and color is "validation" or "sex", use the official Observation.org / sex palettes. Ignored when palette is set. If FALSE, 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 function function(n) that returns n colours. Overrides use_obs_colors. Ignored when color = "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 data is a file path, to filter). WKT, GeoJSON, a path, or sf. Requires sf.

...

Passed to obs_read() when data is a file path.

Value

A ggplot or leaflet object.

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))")
} # }