Skip to contents

Reorder a stack of rasters of species distribution to match the order of the tips of the tree, and get branch length and number of descendants for each species to calculate diversity metrics using phyloraster::geo.phylo(). The branch length and the number of descendants can be calculated based on the full tree or the raster based tree subset. The names must be the same in the phylogenetic tree and in the raster for the same species. For example, if you have the name "Leptodactylus_latrans" in the raster and "Leptodactylus latrans" in the tree, the function will not work. The same goes for uppercase and lowercase letters.

Usage

phylo.pres(x, tree, full_tree_metr = FALSE, ...)

Arguments

x

SpatRaster. A SpatRaster containing presence-absence data (0 or 1) for a set of species.

tree

phylo. A dated tree.

full_tree_metr

logical. Whether edge.path, branch length and number of descendants should be calculated with the full (TRUE) or the prunned tree (FALSE).

...

additional arguments to be passed passed down from a calling function.

Value

Returns a list containing a SpatRaster reordered according to the order that the species appear in the phylogenetic tree, a subtree containing only the species that are in the stack of rasters and finally two named numerical vectors containing the branch length and the number of descendants of each species.

Author

Neander Marcel Heming and Gabriela Alves Ferreira

Examples

# \donttest{
library(phyloraster)
x <- terra::rast(system.file("extdata", "rast.presab.tif",
package="phyloraster"))
tree <- ape::read.tree(system.file("extdata", "tree.nex",
package="phyloraster"))
phylo.pres(x[[1:3]], tree, full_tree_metr = TRUE)
#> Warning: Some species in the phylogeny 'tree' are missing from the
#>                   SpatRaster 'x' and were dropped: Litoria_dorsalis, Litoria_rubella, Litoria_nigrofrenata, Litoria_nasuta, Litoria_tornieri, Litoria_inermis, Litoria_pallida, Litoria_latopalmata, Litoria_bicolor, Litoria_fallax, Litoria_genimaculata, Litoria_andiirrmalin, Litoria_wilcoxii, Litoria_jungguy, Litoria_caerulea, Litoria_gracilenta, Litoria_chloris, Litoria_xanthomera, Cyclorana_brevipes, Cyclorana_novaehollandiae, Cyclorana_manya, Cyclorana_cultripes, Litoria_alboguttata, Cyclorana_longipes, Nyctimystes_dayi, Litoria_nannotis, Litoria_lorica, Litoria_rheocola, Litoria_nyakalensis, Litoria_infrafrenata
#> $x
#> class       : SpatRaster 
#> dimensions  : 90, 68, 3  (nrow, ncol, nlyr)
#> resolution  : 0.1, 0.1  (x, y)
#> extent      : 144.0157, 150.8157, -23.044, -14.044  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326) 
#> source      : rast.presab.tif 
#> names       : Litoria_revelata, Litoria_rothii, Litoria_longirostris 
#> min values  :                0,              0,                    0 
#> max values  :                1,              1,                    1 
#> 
#> $tree
#> 
#> Phylogenetic tree with 3 tips and 1 internal nodes.
#> 
#> Tip labels:
#>   Litoria_revelata, Litoria_rothii, Litoria_longirostris
#> 
#> Unrooted; includes branch lengths.
#> 
#> $edge.path
#>                      [,1] [,2] [,3] [,4] [,5]
#> Litoria_revelata        0    1    0    0    1
#> Litoria_rothii          0    0    1    0    1
#> Litoria_longirostris    0    0    0    1    1
#> 
#> $branch.length
#> [1] 12.680290  0.589016  0.589015  0.589015  0.420985
#> 
#> $n.descendants
#> [1] 0 1 1 1 3
#> 

# using the prunned tree
phylo.pres(x[[1:3]], tree, full_tree_metr = FALSE)
#> Warning: Some species in the phylogeny 'tree' are missing from the
#>                   SpatRaster 'x' and were dropped: Litoria_dorsalis, Litoria_rubella, Litoria_nigrofrenata, Litoria_nasuta, Litoria_tornieri, Litoria_inermis, Litoria_pallida, Litoria_latopalmata, Litoria_bicolor, Litoria_fallax, Litoria_genimaculata, Litoria_andiirrmalin, Litoria_wilcoxii, Litoria_jungguy, Litoria_caerulea, Litoria_gracilenta, Litoria_chloris, Litoria_xanthomera, Cyclorana_brevipes, Cyclorana_novaehollandiae, Cyclorana_manya, Cyclorana_cultripes, Litoria_alboguttata, Cyclorana_longipes, Nyctimystes_dayi, Litoria_nannotis, Litoria_lorica, Litoria_rheocola, Litoria_nyakalensis, Litoria_infrafrenata
#> $x
#> class       : SpatRaster 
#> dimensions  : 90, 68, 3  (nrow, ncol, nlyr)
#> resolution  : 0.1, 0.1  (x, y)
#> extent      : 144.0157, 150.8157, -23.044, -14.044  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326) 
#> source      : rast.presab.tif 
#> names       : Litoria_revelata, Litoria_rothii, Litoria_longirostris 
#> min values  :                0,              0,                    0 
#> max values  :                1,              1,                    1 
#> 
#> $tree
#> 
#> Phylogenetic tree with 3 tips and 1 internal nodes.
#> 
#> Tip labels:
#>   Litoria_revelata, Litoria_rothii, Litoria_longirostris
#> 
#> Unrooted; includes branch lengths.
#> 
#> $edge.path
#>                      [,1] [,2] [,3]
#> Litoria_revelata        1    0    0
#> Litoria_rothii          0    1    0
#> Litoria_longirostris    0    0    1
#> 
#> $branch.length
#> [1] 0.589016 0.589015 0.589015
#> 
#> $n.descendants
#> [1] 1 1 1
#> 
# }