require(ecokit)
require(dplyr)
require(terra)
require(rworldmap)
require(colorRamps)
require(sf)
require(ggplot2)
require(grid)
require(tidyterra)
require(patchwork)Example 6: Descendant-Level Access — Insect Orders (10 km Resolution)
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"),
plot.title = ggplot2::element_text(hjust = 0.5),
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))Descendant-level rasters for Insecta (10 km resolution; 1980–2025)
Previous examples used descendants = "all" to retrieve group-level totals. The ecokit::get_sampling_effort() function also supports descendant-level queries, retrieving rasters for specific orders, classes, or families within a taxonomic group.
This example downloads observation-count rasters for three insect orders — Coleoptera (beetles), Lepidoptera (butterflies and moths), and Hymenoptera (ants, bees, and wasps) — alongside the aggregated Insecta total. Comparing these maps reveals how sampling effort varies markedly among orders. These differences are masked when using only the aggregated group-level raster.
Download: All Insecta (group-level total)
effort_insecta <- ecokit::get_sampling_effort(
group = "insecta", descendants = "all", metric = "n_obs",
years = "total", resolution = 10, out_dir = "effort_maps")
r_insecta <- terra::rast(effort_insecta$local_path[[1]]) %>%
terra::classify(cbind(0, NA)) %>%
log10()Download: 3 orders — Coleoptera (beetles), Lepidoptera (butterflies and moths), Hymenoptera (ants, bees, and wasps)
insect_groups <- c("coleoptera", "lepidoptera", "hymenoptera")
effort_insecta_desc <- ecokit::get_sampling_effort(
group = "insecta", descendants = insect_groups, metric = "n_obs",
years = "total", resolution = 10, out_dir = "effort_maps")dplyr::glimpse(effort_insecta_desc)
# Rows: 3
# Columns: 9
# $ group <chr> "insecta", "insecta", "insecta"
# $ descendant <chr> "coleoptera", "hymenoptera", "lepidoptera"
# $ year <chr> "total", "total", "total"
# $ metric <chr> "n_obs", "n_obs", "n_obs"
# $ resolution <dbl> 10, 10, 10
# $ name <chr> "n_obs_Coleoptera_total_res_10.tif", "n_obs_Hymenoptera_…
# $ id <chr> "6913408a32c4004bc1ddd841", "6916281e843c090b4dfdc3f1", …
# $ local_path <chr> "effort_maps/n_obs_Coleoptera_total_res_10.tif", "effort…
# $ meta <list> [[<NULL>, <NULL>, "n_obs_Coleoptera_total_res_10.tif", "…effort_insecta_desc_r <- terra::rast(effort_insecta_desc$local_path) %>%
terra::classify(cbind(0, NA)) %>%
stats::setNames(insect_groups) %>%
log10()effort_insecta_desc_r
# class : SpatRaster
# size : 2160, 4320, 3 (nrow, ncol, nlyr)
# resolution : 0.08333333, 0.08333333 (x, y)
# extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 (EPSG:4326)
# source(s) : memory
# names : coleoptera, lepidoptera, hymenoptera
# min values : 0, 0, 0
# max values : 5.25101, 5.43261, 5.511117Visualise the rasters - global scale
All Insecta (log10 scale)
ggplot2::ggplot() +
ggplot2::geom_sf(data = global_map, color = "black", size = 0.25, fill = "grey95") +
tidyterra::geom_spatraster(data = r_insecta, 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 = "# observations\n(log10)") +
ggplot2::coord_sf(expand = FALSE) +
common_themeColeoptera (log10 scale)
ggplot2::ggplot() +
ggplot2::geom_sf(data = global_map, color = "black", size = 0.25, fill = "grey95") +
tidyterra::geom_spatraster(data = effort_insecta_desc_r$coleoptera, 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 = "# observations\n(log10)") +
ggplot2::coord_sf(expand = FALSE) +
common_themeLepidoptera (log10 scale)
ggplot2::ggplot() +
ggplot2::geom_sf(data = global_map, color = "black", size = 0.25, fill = "grey95") +
tidyterra::geom_spatraster(data = effort_insecta_desc_r$lepidoptera, 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 = "# observations\n(log10)") +
ggplot2::coord_sf(expand = FALSE) +
common_themeHymenoptera (log10 scale)
ggplot2::ggplot() +
ggplot2::geom_sf(data = global_map, color = "black", size = 0.25, fill = "grey95") +
tidyterra::geom_spatraster(data = effort_insecta_desc_r$hymenoptera, 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 = "# observations\n(log10)") +
ggplot2::coord_sf(expand = FALSE) +
common_themeVisualise the rasters — regional comparison
The following panels crop the rasters to three focal regions (Europe, USA, and India) and display them on a shared colour scale for direct comparison. This reveals how the spatial distribution and intensity of sampling effort differ among insect orders within the same region.