| Title: | Calculate and visualize a phylogenetic diversity indicators based on species occurrence data cubes |
|---|---|
| Description: | A package to calculate and produce a map of phylogenetic diversity scores for each grid cell in the input species occurrences data cube, and calculate the percentage of high PD cells within currently protected areas. You provide a phylogenetic tree, the datacube for the corresponding species is downloaded from GBIF (or user-uploaded), and the package does the rest. |
| Authors: | Lissa Breugelmans [aut, cre] (ORCID: <https://orcid.org/0000-0002-8472-3577>, affiliation: Meise Botanic Garden), Maarten Trekels [aut] (ORCID: <https://orcid.org/0000-0001-8282-8765>, affiliation: Meise Botanic Garden), Louise Hendrickx [aut] (ORCID: <https://orcid.org/0000-0002-9317-7862>, affiliation: Meise Botanic Garden), Ward Langeraert [ctb] (ORCID: <https://orcid.org/0000-0002-5900-8109>, affiliation: Research Institute for Nature and Forest (INBO)), Meise Botanic Garden [cph], European Union's Horizon Europe Research and Innovation Programme (ID No 101059592) [fnd] |
| Maintainer: | Lissa Breugelmans <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-22 18:54:35 UTC |
| Source: | https://github.com/b-cubed-eu/pdindicatoR |
This function aggregates a provided datacube over grid cell id, so that a new
datacube is outputted with 3 variables that contain the lists of species that
are observed for each grid cell (as speciesKeys, ott_id's and names).
aggregate_cube(mcube, timegroup = NULL)aggregate_cube(mcube, timegroup = NULL)
mcube |
An occurrence datacube with appended |
timegroup |
An integer, representing the number of years by which you want to group your occurrence data |
A dataframe with for each grid cell a list of observed species
ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) aggr_cube <- aggregate_cube(mcube)ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) aggr_cube <- aggregate_cube(mcube)
This function uses the table produced by the taxonmatch() function to
create a linking table, and then append the ott_id's as a new field to the
occurrence cube.
append_ott_id(tree, cube, matched)append_ott_id(tree, cube, matched)
tree |
An object of class |
cube |
A dataframe with for selected taxa, the number of occurrences per taxa and per grid cell |
matched |
A dataframe, returned by running the function |
A dataframe which consist of all the data in the original datacube,
appended with columns ott_id, unique_name and orig_tiplabel
ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) aggr_cube <- aggregate_cube(mcube)ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) aggr_cube <- aggregate_cube(mcube)
This function calculates Faith's PD, based on a provided list of species and a phylogenetic tree.
calculate_faithpd(tree, species, mrca_node_id)calculate_faithpd(tree, species, mrca_node_id)
tree |
An object of class |
species |
A character vector where each element is a species, and more specifically, matches a tip label of the phylogenetic tree exactly |
mrca_node_id |
Node id of the taxon that represents the most recent common ancestor of the set of species under study (integer) |
A string that combines "Phylogenetic diversity:" and the calculated value
ex_data <- retrieve_example_data() # determine the most recent common ancestor of all species under study # (not necessarily all species in the tree!) mrca_node_id <- ape::getMRCA(ex_data$tree, ex_data$tree$tip.label) species <- c("Fagus lucida", "Castanopsis fabri", "Quercus_robur") calculate_faithpd(ex_data$tree, species, mrca_node_id)ex_data <- retrieve_example_data() # determine the most recent common ancestor of all species under study # (not necessarily all species in the tree!) mrca_node_id <- ape::getMRCA(ex_data$tree, ex_data$tree$tip.label) species <- c("Fagus lucida", "Castanopsis fabri", "Quercus_robur") calculate_faithpd(ex_data$tree, species, mrca_node_id)
This function calculates which number of species in the provided occurrence cube, is not a tip label of the provided phylogenetic tree.
check_completeness(mcube)check_completeness(mcube)
mcube |
A dataframe which is returned by the function append_ott_id(),
and contains the occurrence datacube with |
a list - first element is the total number of species in the occurrence cube, second element is the number of species lacking in the phylogenetic tree.
ex_data <- retrieve_example_data() mcube<- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) check_completeness(mcube)ex_data <- retrieve_example_data() mcube<- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) check_completeness(mcube)
Convert multisurface object to multipolygon object
convert_multipolygons(object)convert_multipolygons(object)
object |
An object of class multisurface |
An object of class multipolygon
library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree) pd_cube_geo <- right_join(ex_data$grid, pd_cube, by = join_by(CELLCODE == eeacellcode)) cutoff <- 150 pd_cube_geo$pd_high <- as.factor(ifelse((pd_cube_geo$pd > cutoff), 1, 0)) cube_highpd <- pd_cube_geo[pd_cube_geo$pd_high == 1, c("OBJECTID", "CELLCODE", "pd", "geometry", "pd_high")] cube_mp <- convert_multipolygons(cube_highpd)library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree) pd_cube_geo <- right_join(ex_data$grid, pd_cube, by = join_by(CELLCODE == eeacellcode)) cutoff <- 150 pd_cube_geo$pd_high <- as.factor(ifelse((pd_cube_geo$pd > cutoff), 1, 0)) cube_highpd <- pd_cube_geo[pd_cube_geo$pd_high == 1, c("OBJECTID", "CELLCODE", "pd", "geometry", "pd_high")] cube_mp <- convert_multipolygons(cube_highpd)
This function creates, for a geographic area defined by the user, a map with the calculated PD metric for each grid cell and the location of protected nature areas.
generate_map_and_indicator( pd_cube, grid, taxon = NULL, bbox_custom = NULL, cutoff = NULL )generate_map_and_indicator( pd_cube, grid, taxon = NULL, bbox_custom = NULL, cutoff = NULL )
pd_cube |
A dataframe with a variable containing grid cell codes and a variable with calculated pd values (output of the function get_pd_cube()) |
grid |
An sf object with variable detailing grid cell codes and a geometry column |
taxon |
A selected higher taxon, for which the occurrence cube was generated. Used to generate the map's title only. |
bbox_custom |
Optional, numeric vector with custom bounding box coordinates as c(xmin, xmax, ymin, ymax) |
cutoff |
A variable of type numeric which determines the cut-off point between low PD and high PD |
a list PDindicator, which contains one or more maps in it's first
element, and possibly one or more indicator values in it's second element
library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree) PDindicator <- generate_map_and_indicator( pd_cube, ex_data$grid, taxon="Fagales", cutoff=150) map <- PDindicator[[1]] indicator <- PDindicator[[2]]library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree) PDindicator <- generate_map_and_indicator( pd_cube, ex_data$grid, taxon="Fagales", cutoff=150) map <- PDindicator[[1]] indicator <- PDindicator[[2]]
This function determines the MRCA of all species in the datacube and calls the function(s) to calculate PD metrics
get_pd_cube(mcube, tree, timegroup = NULL, metric = "faith")get_pd_cube(mcube, tree, timegroup = NULL, metric = "faith")
mcube |
An occurrence data cube with matched names appended,
product of function |
tree |
A phylogenetic tree with branch lengths |
timegroup |
Optional, an integer which represents the number of years over which occurrences need to be aggregated and the PD value calculated |
metric |
Name of the PD metric to be calculated |
Calculated PD value
library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree, metric="faith")library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree, metric="faith")
This function creates produces an r-shiny app that can showcase multiple PD maps (for separate time periods) in tabs
make_shiny_maps(pd_indicator, plots)make_shiny_maps(pd_indicator, plots)
pd_indicator |
List containing PD plots and indicators, produced by function generate_map_and_indicator.R |
plots |
A list of PD maps produced by the function
|
An r-shiny app with PD maps in tabs
library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree) pd_indicator<- generate_map_and_indicator( pd_cube, ex_data$grid, taxon="Fagales") plots <- pd_indicator[[1]] indicators <- pd_indicator[[2]] ## Not run: make_shiny_maps(pd_indicator, plots)library(dplyr) ex_data <- retrieve_example_data() mcube <- append_ott_id(ex_data$tree, ex_data$cube, ex_data$matched_nona) mcube <- dplyr::filter(mcube, !is.na(ott_id)) pd_cube <- get_pd_cube(mcube, ex_data$tree) pd_indicator<- generate_map_and_indicator( pd_cube, ex_data$grid, taxon="Fagales") plots <- pd_indicator[[1]] indicators <- pd_indicator[[2]] ## Not run: make_shiny_maps(pd_indicator, plots)
This function specifies the paths to the example data and reads the example data files in and processes them so they are ready to be used in the workflow.
retrieve_example_data(data = "all")retrieve_example_data(data = "all")
data |
a list with the names of the datasets to be retrieved. Can be one or multiple of the following: "all", "tree", "cube", "grid", "pa" |
Objects tree (a phylogenetic tree of the order Fagales), cube (an occurrence datacube, see query specifications: https://www.gbif.org/occurrence/download/0004018-241107131044228), grid (EEA 1km grid for study area) and pa (Natura2000 protected area polygons for study area
ex_data <- retrieve_example_data() print(ex_data$tree) print(ex_data$cube) print(ex_data$grid) print(ex_data$pa) print(ex_data$matched_nona)ex_data <- retrieve_example_data() print(ex_data$tree) print(ex_data$cube) print(ex_data$grid) print(ex_data$pa) print(ex_data$matched_nona)
This function matches the tip labels of a phylogenetic tree (Taxon names or OTT id's) with corresponding GBIF id's.
taxonmatch(tree)taxonmatch(tree)
tree |
An object of class |
A dataframe with as variables (among others) the search strings, matched OTT names and id's, gbif id's and original tiplabels
## Not run: ex_data <- retrieve_example_data() # This can take a while! mtable <- taxonmatch(ex_data$tree) ## End(Not run)## Not run: ex_data <- retrieve_example_data() # This can take a while! mtable <- taxonmatch(ex_data$tree) ## End(Not run)