library(terra)
# Load an example SpatRaster with binary presence-absence data
bin_rast <- terra::rast(system.file("extdata", "ref.tif", package = "divraster"))
# Calculate species richness (alpha taxonomic diversity)
richness_map <- spat.alpha2(bin_rast)
richness_map
# Plot the resulting richness map
plot(richness_map, main = "Species Richness Map")
Run the code above in your browser using DataLab