spat.alpha2 {divraster} | R Documentation |
Alternative Method to Calculate Alpha Taxonomic Diversity
Description
Calculates the alpha taxonomic diversity, specifically species richness,
for each cell in a SpatRaster
object containing species presence-absence data.
This function provides a straightforward method to sum the number of species present
in each grid cell.
Usage
spat.alpha2(bin, cores = 1, filename = "")
Arguments
bin |
A |
cores |
A positive integer (default is 1). If |
filename |
Character string. Optional path and filename to save the resulting |
Details
This function calculates species richness by summing the presence (value 1) of all
species across layers for each individual raster cell. It is an alternative
to spat.alpha()
when only Taxonomic Diversity (TD) is required, offering
a more direct and potentially faster computation for this specific metric.
NA
values in input cells are ignored during the sum calculation.
Value
A SpatRaster
object with a single layer named "Richness". Each cell in this
SpatRaster
contains the calculated species richness (number of species present).
The output SpatRaster
will have the same dimensions, resolution, and CRS as the input bin
.
Examples
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")