{"id":22940618,"url":"https://github.com/b-cubed-eu/pdindicator","last_synced_at":"2026-02-25T20:31:42.809Z","repository":{"id":257973518,"uuid":"788483688","full_name":"b-cubed-eu/pdindicatoR","owner":"b-cubed-eu","description":"Repository for the phylogenetic diversity indicator workflow as part of the B3 project. ","archived":false,"fork":false,"pushed_at":"2026-01-15T16:19:23.000Z","size":12281,"stargazers_count":0,"open_issues_count":23,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-01-28T04:19:53.379Z","etag":null,"topics":["biodiversity","conservation","datacube","indicator","phylogenetic-diversity","r"],"latest_commit_sha":null,"homepage":"https://b-cubed-eu.github.io/pdindicatoR/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/b-cubed-eu.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":".zenodo.json"}},"created_at":"2024-04-18T14:00:03.000Z","updated_at":"2025-04-15T09:59:35.000Z","dependencies_parsed_at":"2024-10-31T15:19:27.346Z","dependency_job_id":"d178d08d-9492-4eb3-ad61-565592879907","html_url":"https://github.com/b-cubed-eu/pdindicatoR","commit_stats":null,"previous_names":["b-cubed-eu/pdindicator"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/b-cubed-eu/pdindicatoR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2FpdindicatoR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2FpdindicatoR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2FpdindicatoR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2FpdindicatoR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b-cubed-eu","download_url":"https://codeload.github.com/b-cubed-eu/pdindicatoR/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2FpdindicatoR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29838054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T19:08:47.527Z","status":"ssl_error","status_checked_at":"2026-02-25T18:59:04.705Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["biodiversity","conservation","datacube","indicator","phylogenetic-diversity","r"],"created_at":"2024-12-14T13:29:53.202Z","updated_at":"2026-02-25T20:31:42.792Z","avatar_url":"https://github.com/b-cubed-eu.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(fig.path = \"man/figures/\", echo = TRUE)\n```\n\n# pdindicatoR \u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"139\" alt=\"\" /\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![DOI](https://zenodo.org/badge/788483688.svg)](https://doi.org/10.5281/zenodo.14237551)\n[![CRAN status](https://www.r-pkg.org/badges/version/pdindicatoR)](https://CRAN.R-project.org/package=pdindicatoR)\n[![Release](https://img.shields.io/github/release/b-cubed-eu/pdindicatoR.svg)](https://github.com/b-cubed-eu/pdindicatoR/releases)\n[![R-CMD-check](https://github.com/b-cubed-eu/pdindicatoR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/b-cubed-eu/pdindicatoR/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/b-cubed-eu/pdindicatoR/graph/badge.svg)](https://app.codecov.io/gh/b-cubed-eu/pdindicatoR)\n[![repo status](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)\n\n\u003c!-- badges: end --\u003e\n\nPhylogenetic diversity (PD) is a measure of biodiversity which takes evolution into account. It is calculated as the sum of the lengths of the phylogenetic tree branches representing the minimum tree-spanning path among a group of species.\nPhylogenetic diversity can be used in conservation planning to maximise a variety of features, meaning we do not aim to conserve specific features, but rather want to boost a diverse range of features. Conserving a variety of features could be particularly useful in light of the changing environmental conditions, as we can only guess which features will be important in the future.\n\nIn this package, we provide a workflow to calculate a metric that gives information about how well PD of a certain higher taxonomic group is currently safeguarded by protected areas and a spatial visualisation which can be used to identify potential directions for future expansion of protected areas.\n\n## Installation\n\nYou can install the development version from [GitHub](https://github.com/) with:\n\n```r\n# install.packages(\"remotes\")\nremotes::install_github(\"b-cubed-eu/pdindicatoR\")\n```\n\n## Example workflow\n\nThis example shows a basic workflow for using the functions in the **pdindicatoR** package to calculate PD from a phylogenetic tree and an occurrence cube with occurrences for a certain higher taxon, produce a gridded map of PD scores with colour gradient scale, and show the overlap with protected areas. \n\n```{r packages, message=FALSE, warning=FALSE}\n# Load packages\nlibrary(pdindicatoR)\n\nlibrary(sf)      # working with spatial objects\nlibrary(dplyr)   # data wrangling\n```\n\n### Reading in data\n\nIn order to start the workflow, the user should specify the filepaths to a phylogenetic tree, a species data occurrence cube, and two shapefiles:  \n1) a grid, which should correspond to the grid used to generate the datacube  \n2) a polygon shapefile with boundaries of protected areas. \n\nThe phylogenetic tree should be in either nexus or newick format. The species occurrence cube must have the same variable names as the example datacube (or the columns should be renamed after loading). For more information on how to obtain species occurrence cubes from GBIF and phylogenetic trees to be used with this package, we refer to the vignette 'Finding datasets to use with pdindicatoR'.\n\nThe following functions can be used to read in datafiles:\n\n```r\ntree_path \u003c- \"/path/to/mytree.tre\" \ncube_path \u003c- \"/path/to/mycube.csv\"\ngrid_path \u003c- \"/path/to/grid.shp\"\n\n# Read in newick or nexus format phylogenetic tree\nlibrary(ape)\ntree \u003c- ape::read.tree(tree_path)\n\n# Read in species occurrence data cube. Use appropriate seperator!\ncube \u003c- read.csv(cube_path, stringsAsFactors = FALSE, sep = \"\\t\") \n\n# Read in grid and protected areas shapefile\ngrid \u003c- sf::st_read(grid_filepath)\n```\n\n### Loading example data\n\nFor this example workflow, we will be using the example data that is included in the **pdindicatoR** package.\nThe example data can be loaded by using the function `retrieve_example_data()`\n\n```{r echo=T, results='hide', message=F, warning=F}\nex_data \u003c- retrieve_example_data()\ntree \u003c- ex_data$tree \ncube \u003c- ex_data$cube \ngrid \u003c- ex_data$grid\npa \u003c- ex_data$pa\n```\n\n### Inspect tree and cube\n\nWe plot the tree and print the first lines of the occurrence cube to confirm they are processed correctly.\n\n```{r}\n#| fig.alt: \u003e\n#|   Phylogenetic tree\noptions(width = 1000)\nplot(tree, cex = 0.35, y.lim = 100)\nhead(cube)\n```\n\n### Matching species in phylogenetic tree and datacube\n\nThe leaf labels of a phylogenetic tree downloaded from the OTL database are specified as either species names or OTL id's (`ott_id`). We can use the function `taxonmatch()` to retrieve the corresponding GBIF id's.\n\n```{r}\nmatched \u003c- taxonmatch(tree)\nhead(matched)\n```\n\nCarefully evaluate the table with matches to ensure that matching scores are acceptable and that most species have a corresponding `gbif_id`. Species that cannot be reliable matched or that don't have an associated `gbif_id`, can not contribute to the PD calculation and should be removed.\n\n```{r}\nmatched_nona \u003c- matched %\u003e%\n  dplyr::filter(!is.na(gbif_id))\n```\n\nThen, we can use the function `append_ott_id()` to append the `ott_id`'s as a new variable to the provided datacube, by joining on `gbif_id`.\n\n```{r}\nmcube \u003c- append_ott_id(tree, cube, matched_nona)\nhead(mcube)\n```\n\nWhen species in the datacube are not included in the provided phylogenetic tree, the `ott_id` variable will be `NA`. We can use the function check_completeness() to see how complete the provided phylogenetic tree is.\n```{r}\ncheck_completeness(mcube)\n```\n\nPlease note that occurrence records for species that are not part of the provided phylogenetic tree will need to be removed. In case this number is large, please consider searching for a more complete phylogenetic tree that covers all your species!\n\n```{r}\nmcube \u003c- mcube %\u003e%\n  dplyr::filter(!is.na(ott_id))\n```\n\n### Calculate Phylogenetic Diversity for each grid cell\n\nWe can used the function get_pd_cube() to calculate the PD values per gridcell. This function first creates a new aggregated cube, with a list of observed species for each grid cell. The optional argument `timegroup` can be used to indicate a time interval for which the PD metrics should be calculated, e.g. `timegroup = 5` calculates PD for all occurrences observed within a timespan of 5 years and produces a separate map and indicator for each period. If no `timegroup` argument is specified, all occurrences in the dataset will be aggregated over time. The argument `metric` can be used to specify which PD metric needs to be calculated. The PD values will be appended to the datacube as a new column 'PD'.\n\n```{r}\nPD_cube \u003c- get_pd_cube(mcube, tree, metric = \"faith\")\n```\n\n### Visualize PD on a map \u0026 calculate indicator\n\nFinally we read in the EEA Grid shapefiles and merge them to the occurrence cube by joining on the `eeaCellCode` field. The PD cube can then be plotted and overlaid with a polygon layer depicting the boundaries of WDPA protected areas.\n\n#### Plot PD map\n\nThe function generate_map_and_indicator() can be used to generate a map \nvisualizing phylogenetic diversity covering the geographic area that is used to\ngenerate the occurrence cube.If more detailed maps are desired, the optional \nargument `bbox_custom` can be used to delineate the bounding box. Coordinates \nfor the desired geographic area can be determined using https://epsg.io/ and \nselecting the CRS of the used grid.\n\n```{r echo=T, results='hide', message=F, warning=F}\n#| fig.alt: \u003e\n#|   PD map\nPDindicator \u003c- generate_map_and_indicator(PD_cube, grid, \"Fagales\")\nPDindicator\n\n# Optionally specify a custom bounding box\n# bbox_custom \u003c- c(xmin,xmax,ymin,ymax)\n# PDmap \u003c- generate_map_and_indicator(PD_cube, grid, \"Musteloidea\", bbox_custom)\n```\n\nIf the optional parameter `cutoff` is specified, than this value is used to \nclassify cells as *high PD* cells if their PD exceeds this threshold value. An \nindicator value is then calculated as the percentage of high PD cell \ncenterpoints that fall within the boundaries of protected areas. The result is\nstored as a list, with two maps in the first element (PD map and high/low PD map)\nand the indicator value as the second element. \n\n```{r}\n#| fig.alt: \u003e\n#|   PD map cut off\nPDindicator \u003c- generate_map_and_indicator(\n  PD_cube,\n  grid,\n  \"Fagales\",\n  cutoff = 450)\n\nplots \u003c- PDindicator[[1]]\nindicators \u003c- PDindicator[[2]]\nprint(plots)\nprint(indicators)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb-cubed-eu%2Fpdindicator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb-cubed-eu%2Fpdindicator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb-cubed-eu%2Fpdindicator/lists"}