Macroecological studies have been increasingly utilized in the
context of climate change, necessitating the use of tools to analyze
large datasets. To examine and comprehend the intricate mechanisms that
underlie species distributions and the structure of biological
communities, a diverse array of metrics has been developed. These
metrics encompass alpha and beta diversity patterns across taxonomic
(TD), functional (FD), and phylogenetic (PD) dimensions. The package divraster
addresses a current gap in this field by offering functions to calculate
diversity metrics directly from rasters, eliminating the need for matrix
transformations. This capability is especially valuable when dealing
with extensive datasets, as matrices often impose memory
constraints.
If you find any bug, let us know through divraster
Issues. The development version of divraster
can be
installed from the divraster repository in
Github:
require(devtools)
::install_github("flaviomoc/divraster", build_vignettes = TRUE) devtools
The divraster
package can directly calculate temporal
beta diversity from multilayer rasters for taxonomic (TD), functional
(FD), and phylogenetic (PD) dimensions using the
temp.beta()
function. To our knowledge this method has not
been previously implemented in R
. Furthermore,
divraster
can compute spatial alpha and beta diversity for
TD, FD, and PD by using the spat.alpha()
and
spat.beta()
functions. All beta diversity calculations are
partitioned into replacement and richness differences components.
Additionally, the spat.trait()
function calculates
individual average traits of continuous variables, while the
spat.rand()
calculates standardized effect size for FD and
PD alpha diversity.
Let’s see some examples.
# Presence-absence SpatRaster
<- terra::rast(system.file("extdata",
bin1 "ref_frugivor.tif",
package = "divraster"))
<- terra::rast(system.file("extdata",
bin2 "fut_frugivor.tif",
package = "divraster"))
# Change extension to process faster
::ext(bin1)
terra#> SpatExtent : -41.875, -38.75, -21.375, -13 (xmin, xmax, ymin, ymax)
<- c(-41, -39, -15, -13)
e <- terra::crop(bin1, e)
bin1 <- terra::crop(bin2, e)
bin2
# Species traits
<- read.csv(system.file("extdata",
traits "traits_frugivor.csv",
package = "divraster"),
sep = ";",
row.names = 1)
# Phylogenetic tree
<- ape::read.tree(system.file("extdata",
tree "tree_frugivor.tre",
package = "divraster"))
# Taxonomic
<- divraster::spat.alpha(bin1)
alpha.td #> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#> (status 2 uses the sf package in place of rgdal)
alpha.td#> class : SpatRaster
#> dimensions : 16, 16, 1 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> name : Alpha_TD
#> min value : 0
#> max value : 67
::plot(alpha.td, main = names(alpha.td)) terra
# Functional
<- divraster::spat.alpha(bin1, traits)
alpha.fd
alpha.fd#> class : SpatRaster
#> dimensions : 16, 16, 1 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> name : Alpha_FD
#> min value : 3.723151
#> max value : 4.378846
::plot(alpha.fd, main = names(alpha.fd)) terra
# Phylogenetic
<- divraster::spat.alpha(bin1, tree)
alpha.pd
alpha.pd#> class : SpatRaster
#> dimensions : 16, 16, 1 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> name : Alpha_PD
#> min value : 1523.921
#> max value : 1859.668
::plot(alpha.pd, main = names(alpha.pd)) terra
<- divraster::spat.trait(bin1, traits)
avg.traits1
avg.traits1#> class : SpatRaster
#> dimensions : 16, 16, 12 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Beak.~ulmen, Beak.~Nares, Beak.Width, Beak.Depth, Tarsu~ength, Wing.Length, ...
#> min values : 22.12692, 14.00385, 7.046154, 8.526923, 25.15000, 117.0016, ...
#> max values : 24.52903, 16.41452, 7.804545, 9.601515, 26.29828, 122.0379, ...
::plot(avg.traits1, main = names(avg.traits1)) terra
# Functional
<- divraster::spat.rand(bin1, traits, 3, "site")
ses.fd
ses.fd#> class : SpatRaster
#> dimensions : 16, 16, 4 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Mean_FD, SD_FD, Observed_FD, SES_FD
#> min values : 3.804965, 0.004442342, 3.723151, -11.491807
#> max values : 4.429896, 0.218169533, 4.378846, 2.366919
::plot(ses.fd, main = names(ses.fd)) terra
# Phylogenetic
<- divraster::spat.rand(bin1, tree, 3, "site")
ses.pd
ses.pd#> class : SpatRaster
#> dimensions : 16, 16, 4 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Mean_PD, SD_PD, Observed_PD, SES_PD
#> min values : 1571.430, 1.016952, 1623.451, -24.449621
#> max values : 1873.683, 67.345810, 1880.676, 9.213572
::plot(ses.pd, main = names(ses.pd)) terra
# Taxonomic
<- divraster::spat.beta(bin1)
beta.td
beta.td#> class : SpatRaster
#> dimensions : 16, 16, 3 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Btotal_TD, Brepl_TD, Brich_TD
#> min values : 0.006060606, 0.00000000, 0.004264392
#> max values : 0.109409606, 0.03638009, 0.103181683
::plot(beta.td, main = names(beta.td)) terra
# Functional
<- divraster::spat.beta(bin1, traits)
beta.fd
beta.fd#> class : SpatRaster
#> dimensions : 16, 16, 3 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Btotal_FD, Brepl_FD, Brich_FD
#> min values : 0.0004245858, 0.00000000, 0.0004245858
#> max values : 0.0793045655, 0.01846139, 0.0793045655
::plot(beta.fd, main = names(beta.fd)) terra
# Phylogenetic
<- divraster::spat.beta(bin1, tree)
beta.pd
beta.pd#> class : SpatRaster
#> dimensions : 16, 16, 3 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Btotal_PD, Brepl_PD, Brich_PD
#> min values : 0.002851805, 0.000000000, 0.001618621
#> max values : 0.059656685, 0.008026876, 0.059656685
::plot(beta.pd, main = names(beta.pd)) terra
# Taxonomic
<- divraster::temp.beta(bin1, bin2)
betatemp.td
betatemp.td#> class : SpatRaster
#> dimensions : 16, 16, 3 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Btotal_TD, Brepl_TD, Brich_TD
#> min values : 0.02985075, 0.00000000, 0.02985075
#> max values : 0.31578947, 0.09836066, 0.31578947
::plot(betatemp.td, main = names(betatemp.td)) terra
# Functional
<- divraster::temp.beta(bin1, bin2, traits)
betatemp.fd
betatemp.fd#> class : SpatRaster
#> dimensions : 16, 16, 3 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Btotal_FD, Brepl_FD, Brich_FD
#> min values : 0.01733908, 0.00000000, 0.01012696
#> max values : 0.17031569, 0.03741327, 0.17031569
::plot(betatemp.fd, main = names(betatemp.fd)) terra
# Phylogenetic
<- divraster::temp.beta(bin1, bin2, tree)
betatemp.pd
betatemp.pd#> class : SpatRaster
#> dimensions : 16, 16, 3 (nrow, ncol, nlyr)
#> resolution : 0.125, 0.125 (x, y)
#> extent : -41, -39, -15, -13 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> names : Btotal_PD, Brepl_PD, Brich_PD
#> min values : 0.0120217, 0.0000000, 0.009533166
#> max values : 0.1792291, 0.0394096, 0.179229119
::plot(betatemp.pd, main = names(betatemp.pd)) terra