Plot the spatial sampling simulation (domain, individuals, quadrats, optional gradient)
Source:R/plot_spatial_sampling.R
plot_spatial_sampling.Rd
Creates a publication‑quality map of the simulated landscape. The domain outline is drawn first; simulated individuals (POINT geometries) are overlaid and colored by species; sampling quadrats (POLYGONs) are drawn with IDs. Optionally an environmental raster/heat field is shown underneath for context.
Usage
plot_spatial_sampling(
domain,
species,
quadrats,
P,
show_gradient = FALSE,
env_gradients = NULL,
gradient_type = "temperature_C"
)
Arguments
- domain
An
sf
polygon or multipolygon representing the study area. Geometry should be valid and in the same CRS asspecies
andquadrats
.- species
An
sf
POINT object of individuals with a character/factor column namedspecies
. All points must lie withindomain
for correct visual interpretation (the function does not clip).- quadrats
An
sf
POLYGON/MULTIPOLYGON object with a numeric/integer columnquadrat_id
. Quadrats are drawn as outlines and labeled at their centroids.- P
A named list of plotting/summary parameters. The following fields are read if present (each has a default if missing):
POINT_SIZE
(numeric
, default0.2
) — point size for individuals,POINT_ALPHA
(numeric
in \((0,1)\), default1
) — point transparency,QUADRAT_COLOUR
(character
, default“black”
) — quadrat outline/label colour,BACKGROUND_COLOUR
(character
, default“white”
) — plot background,FOREGROUND_COLOUR
(character
, default”#22223b”
) — domain outline/title colour,N_SPECIES
(integer
) — used to size the palette; inferred from data if absent,N_INDIVIDUALS
(integer
) — used only for the subtitle count if available.
- show_gradient
Logical; if
TRUE
, an environmental surface is drawn beneath the geometries usinggeom_raster()
. DefaultFALSE
.- env_gradients
Required when
show_gradient = TRUE
. A data frame with columnsx
,y
(grid coordinates, in the same CRS units asdomain
) and one or more numeric columns representing environmental variables (e.g.,temperature_C
,elevation_m
,rainfall_mm
). The column named bygradient_type
must exist and be numeric.- gradient_type
Character scalar naming the column in
env_gradients
to plot whenshow_gradient = TRUE
. Default“temperature_C”
. The legend title is derived from this name (underscores replaced with spaces and title‑cased).
Details
Colors for species are drawn from colorspace sequential_hcl
palette “RdPu” (reversed)
and mapped to the unique species present. All layers are plotted in the current display CRS of
the provided sf
objects; ensure consistent CRS across inputs. When show_gradient = TRUE
,
the raster is drawn first with partial transparency so the domain outline and points remain visible.