Title: | Calculate and visualize a phylogenetic diversity indicators based on species occurence data cubes |
---|---|
Description: | A package to calculate and produce a map of phylogenetic diversity scores for each grid cell in the input species occurences 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] (<https://orcid.org/0000-0002-8472-3577>, Meise Botanic Garden), Maarten Trekels [aut] (<https://orcid.org/0000-0001-8282-8765>, Meise Botanic Garden), Louise Hendrickx [aut] (<https://orcid.org/0000-0002-9317-7862>, Meise Botanic Garden), Ward Langeraert [ctb] (<https://orcid.org/0000-0002-5900-8109>, 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.0.2 |
Built: | 2025-02-17 14:21:47 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
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 column ott_id
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)
calculate_faithpd(tree, species, MRCA)
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 of the taxon that represents the most recent common ancestor of the set of species under study |
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 <- 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)
ex_data <- retrieve_example_data() # determine the most recent common ancestor of all species under study # (not necessarily all species in the tree!) MRCA <- 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)
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 |
An sf dataframe containing the calculated PD metrics (column name 'PD') for each grid cell with occurrences of a selected higher taxon, and the geometries of those grid cells. |
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(PDindicator, plots)
make_shiny_maps(PDindicator, plots)
PDindicator |
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) PDindicator<- generate_map_and_indicator( PD_cube, ex_data$grid, taxon="Fagales") plots <- PDindicator[[1]] indicators <- PDindicator[[2]] ## Not run: make_shiny_maps(PDindicator, 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) PDindicator<- generate_map_and_indicator( PD_cube, ex_data$grid, taxon="Fagales") plots <- PDindicator[[1]] indicators <- PDindicator[[2]] ## Not run: make_shiny_maps(PDindicator, 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 columns ott_id
and gbif_id
## 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)