require(ecokit)
require(dplyr)
require(terra)
require(rworldmap)
require(colorRamps)
require(sf)
require(ggplot2)
require(grid)
require(tidyterra)Example 3: Cumulative Species Richness Across All Taxonomic Groups
Note: This example is part of the Global Sampling Effort Dataset repository, which provides pre-computed, taxon-stratified rasters of spatial sampling effort derived from GBIF occurrence records. For an overview of all available examples, taxonomic groups, etc., see the main page. If you use these data or code, please cite:
El-Gabbas, A. (2026) A global, taxon-stratified, high-resolution sampling-effort dataset from GBIF for bias-aware ecological modelling. Diversity and Distributions 32, no. 5: e70205. https://doi.org/10.1111/ddi.70205..
Setup: Load required packages and define plot theme
global_map <- sf::st_as_sf(rworldmap::getMap(resolution = "high"))common_theme <- ggplot2::theme_void() +
ggplot2::theme(
plot.margin = grid::unit(c(0, 0, 0, 0), "lines"),
legend.position = "right",
legend.box.spacing = grid::unit(10, "pt"),
legend.margin = ggplot2::margin(),
legend.title = ggplot2::element_text(size = 7),
legend.text = ggplot2::element_text(size = 7))Cumulative recorded number of recorded species (5 km resolution; 1980–2025)
This example retrieves the cumulative number of recorded species across all taxonomic groups at 5 km resolution, aggregated over the full time period (1980–2025). The files are saved to the effort_maps directory.
Unlike Examples 1 and 2, which focus on birds only, this example covers all available taxonomic groups combined.
# Retrieve cumulative number of species (all groups, all years, 5 km grid)
effort_all <- ecokit::get_sampling_effort(
group = "all", descendants = "all", metric = "n_sp",
years = "total", resolution = 5, out_dir = "effort_maps")Visualise the raster
Load and transform the raster
Load the downloaded raster, replace zeros with NA (to avoid -Inf after transformation), and apply a log10 transformation for visualisation:
r_map <- terra::rast(effort_all$local_path[[1]]) %>%
terra::classify(cbind(0, NA)) %>%
log10()Global map (log10 scale)
The map below shows the cumulative number of distinct species recorded per 5 km grid cell, illustrating geographic variation in taxonomic coverage.
ggplot2::ggplot() +
ggplot2::geom_sf(data = global_map, color = "black", size = 0.25, fill = "grey95") +
tidyterra::geom_spatraster(data = r_map, maxcell = 2.3e6) +
ggplot2::scale_fill_gradientn(colours = colorRamps::matlab.like2(100), na.value = "transparent") +
ggplot2::geom_sf(data = global_map, color = "grey60", size = 0.125, fill = "transparent") +
ggplot2::labs(fill = "# species\n(log10)") +
ggplot2::coord_sf(expand = FALSE) +
common_themeEurope (log10 scale)
r_map2 <- terra::crop(r_map, terra::ext(-11, 37.5, 35, 71))
ggplot2::ggplot() +
tidyterra::geom_spatraster(data = r_map2, maxcell = 2.3e6) +
ggplot2::scale_fill_gradientn(colours = colorRamps::matlab.like2(100), na.value = "transparent") +
ggplot2::geom_sf(data = global_map, color = "grey30", size = 0.125, fill = "transparent") +
ggplot2::labs(fill = "# species\n(log10)") +
ggplot2::coord_sf(expand = FALSE, xlim = c(-11, 37.5), ylim = c(35, 71)) +
common_themeUSA (log10 scale)
r_map2 <- terra::crop(r_map, terra::ext(-125, -66.5, 24.5, 49.5))
ggplot2::ggplot() +
tidyterra::geom_spatraster(data = r_map2, maxcell = 2.3e6) +
ggplot2::scale_fill_gradientn(colours = colorRamps::matlab.like2(100), na.value = "transparent") +
ggplot2::geom_sf(data = global_map, color = "grey30", size = 0.5, fill = "transparent") +
ggplot2::labs(fill = "# species\n(log10)") +
ggplot2::coord_sf(expand = FALSE, xlim = c(-125, -66.5), ylim = c(24.5, 49.5)) +
common_themeIndia (log10 scale)
r_map2 <- terra::crop(r_map, terra::ext(68.1, 97.4, 6.7, 35.5))
ggplot2::ggplot() +
tidyterra::geom_spatraster(data = r_map2, maxcell = 2.3e6) +
ggplot2::scale_fill_gradientn(colours = colorRamps::matlab.like2(100), na.value = "transparent") +
ggplot2::geom_sf(data = global_map, color = "grey30", size = 0.5, fill = "transparent") +
ggplot2::labs(fill = "# species\n(log10)") +
ggplot2::coord_sf(expand = FALSE, xlim = c(68.1, 97.4), ylim = c(6.7, 35.5)) +
common_theme