Title: | Functional Biogeography Analyses |
---|---|
Description: | Helps users with analyses in functional biogeogeography by loading and combining data, computing trait coverage, as well as computing functional diversity indices, drawing maps, correlating them with the environment, and upscaling assemblages. |
Authors: | Nicolas Casajus [aut, cre, cph]
|
Maintainer: | Nicolas Casajus <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.0.9000 |
Built: | 2025-02-14 15:29:14 UTC |
Source: | https://github.com/FRBCesab/funbiogeo |
This function helps aggregating site data along a coarser grid. The idea is that you have any type of data at the site scale (diversity metrics, environmental data, etc.) but you would like to work on it at a coarser scale, or you want to visualize it at that scale. This function helps you do exactly that.
fb_aggregate_site_data(site_locations, site_data, agg_grid, fun = mean)
fb_aggregate_site_data(site_locations, site_data, agg_grid, fun = mean)
site_locations |
an |
site_data |
a |
agg_grid |
a |
fun |
the function used to aggregate points values when there are
multiple points in one cell. Default is |
A SpatRaster
object with as many layers as columns in site_data
.
## Import grid ---- tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") tavg <- terra::rast(tavg) ## Rasterize 3 first species counts ---- fb_aggregate_site_data( woodiv_locations, woodiv_site_species[, 1:4], tavg, fun = sum )
## Import grid ---- tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") tavg <- terra::rast(tavg) ## Rasterize 3 first species counts ---- fb_aggregate_site_data( woodiv_locations, woodiv_site_species[, 1:4], tavg, fun = sum )
For each species computes the percentage of sites where the species is present (distribution value higher than 0 and non-NA).
fb_count_sites_by_species(site_species)
fb_count_sites_by_species(site_species)
site_species |
a |
A three-column data.frame
with:
species
: the name of the species;
n_sites
: the number of sites where the species is present;
coverage
: the percentage of sites where the species is present.
site_coverage_by_species <- fb_count_sites_by_species(woodiv_site_species) head(site_coverage_by_species)
site_coverage_by_species <- fb_count_sites_by_species(woodiv_site_species) head(site_coverage_by_species)
For each site computes the proportion of species present (distribution value higher than 0 and non-NA) compared to all species provided. For example, a site could contain only 20% of all species provided.
fb_count_species_by_site(site_species)
fb_count_species_by_site(site_species)
site_species |
a |
A three-column data.frame
with:
site
: the name of the site;
n_species
: the number of present species;
coverage
: the percentage of present species.
species_coverage_by_site <- fb_count_species_by_site(woodiv_site_species) head(species_coverage_by_site)
species_coverage_by_site <- fb_count_species_by_site(woodiv_site_species) head(species_coverage_by_site)
For each trait computes the percentage of species without NA
(missing
trait values).
fb_count_species_by_trait(species_traits)
fb_count_species_by_trait(species_traits)
species_traits |
a |
A three-column data.frame
with:
trait
: the name of the trait;
n_species
: the number of species with non-missing value for the trait;
coverage
: the percentage of species with non-missing value for the trait.
species_coverage_by_trait <- fb_count_species_by_trait(woodiv_traits) head(species_coverage_by_trait)
species_coverage_by_trait <- fb_count_species_by_trait(woodiv_traits) head(species_coverage_by_trait)
For each species computes the percentage of traits without NA
(missing
trait values).
fb_count_traits_by_species(species_traits)
fb_count_traits_by_species(species_traits)
species_traits |
a |
A three-column data.frame
with:
species
: the name of the species;
n_traits
: the number of traits with non-missing value for the species;
coverage
: the percentage of traits with non-missing value for the
species.
trait_coverage_by_species <- fb_count_traits_by_species(woodiv_traits) head(trait_coverage_by_species)
trait_coverage_by_species <- fb_count_traits_by_species(woodiv_traits) head(trait_coverage_by_species)
This function returns the community-weighted mean of provided trait values.
It only works with quantitative traits and will warn you otherwise.
It will remove species that either have NA
values in the site_species
input or NA
values as their trait.
fb_cwm(site_species, species_traits)
fb_cwm(site_species, species_traits)
site_species |
a |
species_traits |
a |
A data.frame
with sites in rows and the following variables:
site
, the site label,
trait
, the trait label as provided in species_traits
,
and cwm
, the community-weighted means of quantitative traits values.
site_cwm <- fb_cwm(head(woodiv_site_species), woodiv_traits) head(site_cwm)
site_cwm <- fb_cwm(head(woodiv_site_species), woodiv_traits) head(site_cwm)
Selects sites (rows) for which the percentage of present species (distribution value higher than 0 and non-NA) is higher than a threshold.
fb_filter_sites_by_species_coverage( site_species, threshold_species_proportion = 0 )
fb_filter_sites_by_species_coverage( site_species, threshold_species_proportion = 0 )
site_species |
a |
threshold_species_proportion |
a numeric of length 1 between 0 and 1. The percentage of species coverage threshold. |
A subset of site_species
with sites covered by X% of species.
# Get sites with more than 40% of the species new_site_species <- fb_filter_sites_by_species_coverage( woodiv_site_species, threshold_species_proportion = 0.4 ) # There are now only 148 sites dim(new_site_species) new_site_species[1:3, 1:4]
# Get sites with more than 40% of the species new_site_species <- fb_filter_sites_by_species_coverage( woodiv_site_species, threshold_species_proportion = 0.4 ) # There are now only 148 sites dim(new_site_species) new_site_species[1:3, 1:4]
...
fb_filter_sites_by_trait_coverage( site_species, species_traits, threshold_traits_proportion = 1 )
fb_filter_sites_by_trait_coverage( site_species, species_traits, threshold_traits_proportion = 1 )
site_species |
a |
species_traits |
a |
threshold_traits_proportion |
a numeric of length 1 between 0 and 1. The percentage trait coverage threshold |
A subset of site_species
with sites covered by X% of
abundance/coverage considering all provided traits.
# Filter all the sites where all species have known traits new_site_species <- fb_filter_sites_by_trait_coverage( woodiv_site_species, woodiv_traits ) # There is only one such site nrow(new_site_species) # Filter sites where at least 80% of species have known traits new_site_species_2 <- fb_filter_sites_by_trait_coverage( woodiv_site_species, woodiv_traits, threshold_traits_proportion = 0.8 ) # There are now four sites nrow(new_site_species_2)
# Filter all the sites where all species have known traits new_site_species <- fb_filter_sites_by_trait_coverage( woodiv_site_species, woodiv_traits ) # There is only one such site nrow(new_site_species) # Filter sites where at least 80% of species have known traits new_site_species_2 <- fb_filter_sites_by_trait_coverage( woodiv_site_species, woodiv_traits, threshold_traits_proportion = 0.8 ) # There are now four sites nrow(new_site_species_2)
Selects species (columns) for which the percentage of sites where the species is present (distribution value higher than 0 and non-NA) is higher than a threshold.
fb_filter_species_by_site_coverage( site_species, threshold_sites_proportion = 0 )
fb_filter_species_by_site_coverage( site_species, threshold_sites_proportion = 0 )
site_species |
a |
threshold_sites_proportion |
a numeric of length 1 between 0 and 1. The percentage of sites coverage threshold. |
A subset of site_species
with species with a prevalence higher
than threshold_sites_proportion
.
# Filter species present in at least 10% of the sites new_site_species <- fb_filter_species_by_site_coverage( woodiv_site_species, threshold_sites_proportion = 0.1 ) new_site_species[1:3, 1:4] # There are now only 84 species (instead of 149) ncol(new_site_species)
# Filter species present in at least 10% of the sites new_site_species <- fb_filter_species_by_site_coverage( woodiv_site_species, threshold_sites_proportion = 0.1 ) new_site_species[1:3, 1:4] # There are now only 84 species (instead of 149) ncol(new_site_species)
Selects species (rows) for which the percentage of traits without
NA
(missing trait values) is higher than a threshold.
fb_filter_species_by_trait_coverage( species_traits, threshold_traits_proportion = 0 )
fb_filter_species_by_trait_coverage( species_traits, threshold_traits_proportion = 0 )
species_traits |
a |
threshold_traits_proportion |
a numeric of length 1 between 0 and 1. The percentage of traits coverage threshold. |
A subset of species_traits
with species covered by X% of traits.
# Filter species that have at least 60% of the traits described new_species_traits <- fb_filter_species_by_trait_coverage( woodiv_traits, threshold_traits_proportion = 0.6 ) # There are now only 93 species nrow(new_species_traits)
# Filter species that have at least 60% of the traits described new_species_traits <- fb_filter_species_by_trait_coverage( woodiv_traits, threshold_traits_proportion = 0.6 ) # There are now only 93 species nrow(new_species_traits)
Selects traits (columns) for which the percentage of species without
NA
(missing trait values) is higher than a threshold.
fb_filter_traits_by_species_coverage( species_traits, threshold_species_proportion = 0 )
fb_filter_traits_by_species_coverage( species_traits, threshold_species_proportion = 0 )
species_traits |
a |
threshold_species_proportion |
|
A subset of species_traits
with traits for the specified
proportion of species.
# Filter traits that have at least 60% non-missing values new_species_traits <- fb_filter_traits_by_species_coverage( woodiv_traits, threshold_species_proportion = 0.6 ) # There are now only 2 traits ncol(new_species_traits)
# Filter traits that have at least 60% non-missing values new_species_traits <- fb_filter_traits_by_species_coverage( woodiv_traits, threshold_species_proportion = 0.6 ) # There are now only 2 traits ncol(new_species_traits)
Convert a flat data.frame
with site coordinates into a proper sf
object
that can then be used by other functions. This function assumes that
the coordinates are given in WGS84 (longitude vs. latitude). The function
automatically removes repeated coordinates from the input dataset.
fb_format_site_locations( data, site, longitude, latitude, crs = sf::st_crs(4326), na_rm = FALSE )
fb_format_site_locations( data, site, longitude, latitude, crs = sf::st_crs(4326), na_rm = FALSE )
data |
a |
site |
a |
longitude |
a |
latitude |
a |
crs |
a |
na_rm |
a logical value. If |
An sf
object with a site
column specifying site coordinates.
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) site_locations <- fb_format_site_locations( all_data, "site", "longitude", "latitude" ) head(site_locations)
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) site_locations <- fb_format_site_locations( all_data, "site", "longitude", "latitude" ) head(site_locations)
Convert a flat data.frame
with species occurrence/abundance at site level
into a proper data.frame
object that can then be used by other functions.
The final output contains sites in rows and species in columns.
fb_format_site_species(data, site, species, value, na_to_zero = TRUE)
fb_format_site_species(data, site, species, value, na_to_zero = TRUE)
data |
a |
site |
a |
species |
a |
value |
a |
na_to_zero |
a logical value. If |
A data.frame
with sites in rows and species in columns. The first
column is named "site"
and contains the name of the sites.
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) site_species <- fb_format_site_species(all_data, "site", "species", "count") site_species[1:3, 1:4]
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) site_species <- fb_format_site_species(all_data, "site", "species", "count") site_species[1:3, 1:4]
Convert a flat data.frame
with species names and species (supra-)category
(e.g. family, order, endemism status, etc.) into a proper data.frame
object
that can then be used by other functions.
The final output contains species in rows and two columns (species name and
species category).
fb_format_species_categories(data, species, category)
fb_format_species_categories(data, species, category)
data |
a |
species |
a |
category |
a |
A data.frame
with species in rows and two columns (species name and
species category).
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) species_categories <- fb_format_species_categories( all_data, "species", "genus" ) species_categories[1:6, ]
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) species_categories <- fb_format_species_categories( all_data, "species", "genus" ) species_categories[1:6, ]
Convert a flat data.frame
with traits values for different species
into a proper data.frame
object that can then be used by other functions.
The final output contains species in rows and traits in columns.
fb_format_species_traits(data, species, traits)
fb_format_species_traits(data, species, traits)
data |
a |
species |
a |
traits |
a |
A data.frame
with species in rows and traits in columns, with the
first column names "species"
containing the species names.
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) traits <- c("plant_height", "seed_mass", "sla", "wood_density") species_traits <- fb_format_species_traits(all_data, "species", traits) head(species_traits)
filename <- system.file( "extdata", "woodiv_raw_data.csv", package = "funbiogeo" ) all_data <- read.csv(filename) head(all_data) traits <- c("plant_height", "seed_mass", "sla", "wood_density") species_traits <- fb_format_species_traits(all_data, "species", traits) head(species_traits)
Compute trait coverage for all sites, i.e., the percentage of total
abundance/presence of species that have traits data compared to total
species. This function assumes that all species provided in the traits dataset have
all their traits specified (meaning that all species have either known or
NA
values reported as their traits).
The coverage of each trait separately is returned as well as all traits taken
together if wanted.
fb_get_all_trait_coverages_by_site( site_species, species_traits, all_traits = TRUE )
fb_get_all_trait_coverages_by_site( site_species, species_traits, all_traits = TRUE )
site_species |
a |
species_traits |
a |
all_traits |
a logical (default = |
a data.frame with a column with sites and one column per provided
trait giving its coverage (percent species per site, weighted by abundance
that have trait data), and, when argument all_traits = TRUE
,
an additional column named all_traits
considering the coverage of all
traits taken together.
site_trait_cov <- fb_get_all_trait_coverages_by_site( woodiv_site_species, woodiv_traits ) head(site_trait_cov)
site_trait_cov <- fb_get_all_trait_coverages_by_site( woodiv_site_species, woodiv_traits ) head(site_trait_cov)
Extract Raster Values at Location of Sites
fb_get_environment(site_locations, environment_raster)
fb_get_environment(site_locations, environment_raster)
site_locations |
an |
environment_raster |
a |
A data.frame
with average environmental values (columns) per site
(rows), with the first column being "site"
indicating site names.
## Import climate rasters ---- prec <- system.file("extdata", "annual_tot_prec.tif", package = "funbiogeo") tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") layers <- terra::rast(c(tavg, prec)) fb_get_environment(head(woodiv_locations), layers)
## Import climate rasters ---- prec <- system.file("extdata", "annual_tot_prec.tif", package = "funbiogeo") tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") layers <- terra::rast(c(tavg, prec)) fb_get_environment(head(woodiv_locations), layers)
This function computes trait coverage for each site for different trait combinations. If not provided, consider all possible trait combinations. The function will not run if the total number of combinations given is over 10,000.
fb_get_trait_combination_coverage( site_species, species_traits, comb_size = NULL )
fb_get_trait_combination_coverage( site_species, species_traits, comb_size = NULL )
site_species |
a |
species_traits |
a |
comb_size |
an integer vector defining one or more sizes of combinations
(default: |
a data.frame with the following columns:
site
with the site indices from site_species
,
combination_length
with the number of traits in given combinations,
combination_name
with the name of the trait combination (concatenated
trait names with __
),
trait_coverage
the corresponding trait coverage for the given
trait combination and site.
# Compute Coverages using All Trait Combinations all_combinations = fb_get_trait_combination_coverage( woodiv_site_species, woodiv_traits ) # Get only combinations of 3 traits three_traits = fb_get_trait_combination_coverage( woodiv_site_species, woodiv_traits, 3 ) # Combinations of 2, 3, and 4 traits two_to_four = fb_get_trait_combination_coverage( woodiv_site_species, woodiv_traits, 2:4 )
# Compute Coverages using All Trait Combinations all_combinations = fb_get_trait_combination_coverage( woodiv_site_species, woodiv_traits ) # Get only combinations of 3 traits three_traits = fb_get_trait_combination_coverage( woodiv_site_species, woodiv_traits, 3 ) # Combinations of 2, 3, and 4 traits two_to_four = fb_get_trait_combination_coverage( woodiv_site_species, woodiv_traits, 2:4 )
Compute trait coverage for all sites, i.e., the percentage of total
abundance/presence of species that have traits data compared to total
species.
This function assumes that all species provided in the traits dataset have
all their traits specified (meaning that all species have either known or
NA
values reported as their traits).
NB: this function returns trait coverage using all traits
provided in the input species_traits
data.frame.
fb_get_trait_coverage_by_site(site_species, species_traits)
fb_get_trait_coverage_by_site(site_species, species_traits)
site_species |
a |
species_traits |
a |
A data.frame
with n
rows (where n
is the number of sites) and
two columns: site
, the site label, and trait_coverage
, the percent of
total abundance/presence of species that have traits data.
site_trait_cov <- fb_get_trait_coverage_by_site( woodiv_site_species, woodiv_traits ) head(site_trait_cov)
site_trait_cov <- fb_get_trait_coverage_by_site( woodiv_site_species, woodiv_traits ) head(site_trait_cov)
Creates an R Markdown (.Rmd
) report from a template to explore and
summarize users data. User can modify this report and use the function
rmarkdown::render()
to convert this .Rmd
in different formats:
HTML document (output_format = "bookdown::html_document2"
);
PDF document (output_format = "bookdown::pdf_document2"
);
Word document (output_format = "bookdown::word_document2"
);
HTML, PDF and Word documents (output_format = "all"
).
fb_make_report( path = ".", filename = NULL, title = NULL, author = NULL, species_traits_name, site_species_name, site_locations_name, overwrite = FALSE, open = TRUE )
fb_make_report( path = ".", filename = NULL, title = NULL, author = NULL, species_traits_name, site_species_name, site_locations_name, overwrite = FALSE, open = TRUE )
path |
a |
filename |
a |
title |
a |
author |
a |
species_traits_name |
a |
site_species_name |
a |
site_locations_name |
a |
overwrite |
a logical. If this file is already present and
|
open |
a logical. If |
No return value.
# Create temporary folder temp_path <- tempdir() # Create report fb_make_report( path = temp_path, author = "Casajus N. and Grenié M.", species_traits_name = "woodiv_traits", site_species_name = "woodiv_site_species", site_locations_name = "woodiv_locations", open = FALSE ) ## Not run: # Open Rmd file ---- utils::file.edit(file.path(temp_path, "funbiogeo_report.Rmd")) # Render Rmd file ---- rmarkdown::render( file.path(temp_path, "funbiogeo_report.Rmd"), output_format = "all" ) ## End(Not run)
# Create temporary folder temp_path <- tempdir() # Create report fb_make_report( path = temp_path, author = "Casajus N. and Grenié M.", species_traits_name = "woodiv_traits", site_species_name = "woodiv_site_species", site_locations_name = "woodiv_locations", open = FALSE ) ## Not run: # Open Rmd file ---- utils::file.edit(file.path(temp_path, "funbiogeo_report.Rmd")) # Render Rmd file ---- rmarkdown::render( file.path(temp_path, "funbiogeo_report.Rmd"), output_format = "all" ) ## End(Not run)
Map a Single Raster Layer
fb_map_raster(x, ...)
fb_map_raster(x, ...)
x |
a |
... |
other parameters passed to |
A ggplot
object.
library(ggplot2) ## Load raster ---- tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") tavg <- terra::rast(tavg) ## Default map ---- fb_map_raster(tavg) ## Map with custom theme ---- fb_map_raster(tavg, legend.position = "bottom") ## Advanced customization ---- my_map <- fb_map_raster(tavg) + scale_fill_distiller("Temperature", palette = "Spectral") + theme(legend.position = "bottom") + ggtitle("Mean annual temperature in Western Europe") my_map ## Map w/o annotation ---- fb_map_raster(tavg) + theme_void() + theme(legend.position = "none")
library(ggplot2) ## Load raster ---- tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") tavg <- terra::rast(tavg) ## Default map ---- fb_map_raster(tavg) ## Map with custom theme ---- fb_map_raster(tavg, legend.position = "bottom") ## Advanced customization ---- my_map <- fb_map_raster(tavg) + scale_fill_distiller("Temperature", palette = "Spectral") + theme(legend.position = "bottom") + ggtitle("Mean annual temperature in Western Europe") my_map ## Map w/o annotation ---- fb_map_raster(tavg) + theme_void() + theme(legend.position = "none")
From the site-locations data and a dataset organized by site, plot a map of this information. The returned plot is as little customized as possible to let the user do the customization.
fb_map_site_data(site_locations, site_data, selected_col)
fb_map_site_data(site_locations, site_data, selected_col)
site_locations |
an |
site_data |
|
selected_col |
|
a ggplot
object.
site_rich <- fb_count_species_by_site(woodiv_site_species) # Map of Species Richness rich_map <- fb_map_site_data(woodiv_locations, site_rich, "n_species") rich_map # Customize the map rich_map + ggplot2::scale_fill_viridis_c("Species Richness")
site_rich <- fb_count_species_by_site(woodiv_site_species) # Map of Species Richness rich_map <- fb_map_site_data(woodiv_locations, site_rich, "n_species") rich_map # Customize the map rich_map + ggplot2::scale_fill_viridis_c("Species Richness")
Returns a ggplot2
map of sites colored by trait coverage (proportion
of species having a known trait value). By default shows one plot for each
trait and add an additional facet named "all_traits"
considering the
trait coverage with all traits taken together.
fb_map_site_traits_completeness( site_locations, site_species, species_traits, all_traits = TRUE )
fb_map_site_traits_completeness( site_locations, site_species, species_traits, all_traits = TRUE )
site_locations |
an |
site_species |
a |
species_traits |
a |
all_traits |
a logical (default = |
a 'ggplot2' object
fb_map_site_traits_completeness( woodiv_locations, woodiv_site_species, woodiv_traits )
fb_map_site_traits_completeness( woodiv_locations, woodiv_site_species, woodiv_traits )
Plots the distributions of trait coverage across site, i.e. the proportion of
species weighted by abundance with known trait values, for each trait
separately and all traits taken together.
The trait distributions are ordered from the lowest to the highest average
trait coverage (top to bottom). The top always displays a distribution named
"all_traits"
that contains the distribution of coverage all traits taken
together.
fb_plot_distribution_site_trait_coverage( site_species, species_traits, species_categories = NULL, all_traits = TRUE )
fb_plot_distribution_site_trait_coverage( site_species, species_traits, species_categories = NULL, all_traits = TRUE )
site_species |
a |
species_traits |
a |
species_categories |
(default = |
all_traits |
a logical (default = |
a 'ggplot2' object
fb_plot_distribution_site_trait_coverage(woodiv_site_species, woodiv_traits)
fb_plot_distribution_site_trait_coverage(woodiv_site_species, woodiv_traits)
Represent all species in each function of the number of sites they occupy. The species are ordered from the ones that occupy the least number of sites from the ones that occupy the most. The number of site is indicated at the bottom x-axis, while the top x-axis represents the proportion of occupied sites. The left y-axis label species names and their rank by increasing prevalence. The user can supplied a threshold of sites to see how many species occupy more or less than the given proportion of sites.
fb_plot_number_sites_by_species( site_species, threshold_sites_proportion = NULL )
fb_plot_number_sites_by_species( site_species, threshold_sites_proportion = NULL )
site_species |
a |
threshold_sites_proportion |
a numeric of length 1 between 0 and 1. The percentage of sites coverage threshold. |
a ggplot2
object
fb_plot_number_sites_by_species(woodiv_site_species) # Add a vertical cutoff line (40% of sites) fb_plot_number_sites_by_species(woodiv_site_species, 0.4)
fb_plot_number_sites_by_species(woodiv_site_species) # Add a vertical cutoff line (40% of sites) fb_plot_number_sites_by_species(woodiv_site_species, 0.4)
Display a lollipop graph showing the number and proportion of species with non-NA trait for each trait ranked in decreasing order.
fb_plot_number_species_by_trait( species_traits, species_categories = NULL, threshold_species_proportion = NULL )
fb_plot_number_species_by_trait( species_traits, species_categories = NULL, threshold_species_proportion = NULL )
species_traits |
a |
species_categories |
(default = |
threshold_species_proportion |
|
a ggplot2 object
fb_plot_number_species_by_trait(woodiv_traits) # Add a vertical cutoff line (12.5% of species) fb_plot_number_species_by_trait(woodiv_traits, NULL, 1/8)
fb_plot_number_species_by_trait(woodiv_traits) # Add a vertical cutoff line (12.5% of species) fb_plot_number_species_by_trait(woodiv_traits, NULL, 1/8)
Display a graph showing the number (and proportion) of species having at least 0, 1, etc. number of traits. It provides a lollipop graph to examine which number of trait cover a certain proportion of the species. This plot doesn't show which traits are concerned.
fb_plot_number_traits_by_species( species_traits, species_categories = NULL, threshold_species_proportion = NULL )
fb_plot_number_traits_by_species( species_traits, species_categories = NULL, threshold_species_proportion = NULL )
species_traits |
a |
species_categories |
(default = |
threshold_species_proportion |
|
a ggplot2
object
fb_plot_number_traits_by_species(woodiv_traits) # Add a vertical cutoff line (33% of the species) fb_plot_number_traits_by_species( woodiv_traits, threshold_species_proportion = 1/3 )
fb_plot_number_traits_by_species(woodiv_traits) # Add a vertical cutoff line (33% of the species) fb_plot_number_traits_by_species( woodiv_traits, threshold_species_proportion = 1/3 )
Plot a figure showing the average environmental space of given sites compared to a full environmental vector. For the sake of simplicity only represents the figure along two environmental axes. The average environmental value are extracted for each site.
fb_plot_site_environment( site_locations, environment_raster, first_layer = names(environment_raster)[1], second_layer = names(environment_raster)[2] )
fb_plot_site_environment( site_locations, environment_raster, first_layer = names(environment_raster)[1], second_layer = names(environment_raster)[2] )
site_locations |
an |
environment_raster |
a |
first_layer |
|
second_layer |
|
a ggplot
object
# Import climate rasters prec <- system.file("extdata", "annual_tot_prec.tif", package = "funbiogeo") tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") layers <- terra::rast(c(tavg, prec)) # Make plot (show environmental position of 6 first sites) fb_plot_site_environment(head(woodiv_locations), layers)
# Import climate rasters prec <- system.file("extdata", "annual_tot_prec.tif", package = "funbiogeo") tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo") layers <- terra::rast(c(tavg, prec)) # Make plot (show environmental position of 6 first sites) fb_plot_site_environment(head(woodiv_locations), layers)
Display a binary heatmap visualizing the site x traits matrix with colors
displaying the proportion of occurring species with known trait values.
Traits are ordered from the most to the least known (left to right).
Sites are ordered from the ones with highest to lowest overall trait coverage
(bottom to top). The site average proportion of species with known trait
for each trait (across all sites) is shown in the x-axis labels.
An additional column at the very right of the plot named "all_traits"
shows a summary considering traits together.
fb_plot_site_traits_completeness( site_species, species_traits, species_categories = NULL, all_traits = TRUE )
fb_plot_site_traits_completeness( site_species, species_traits, species_categories = NULL, all_traits = TRUE )
site_species |
a |
species_traits |
a |
species_categories |
(default = |
all_traits |
a logical (default = |
a ggplot2 object
fb_plot_site_traits_completeness(woodiv_site_species, woodiv_traits)
fb_plot_site_traits_completeness(woodiv_site_species, woodiv_traits)
Display a binary heatmap visualizing the species x traits matrix with colors
displaying present and missing traits. Traits are ordered from the most to
the least known (left to right).
Species are ordered from the ones with most to the ones with least traits
(bottom to top). The proportion of species with non-missing traits is shown
on the x-axis labels.
An additional column at the very right of the plot named "all_traits"
shows a summary considering if all other traits are known.
fb_plot_species_traits_completeness( species_traits, species_categories = NULL, all_traits = TRUE )
fb_plot_species_traits_completeness( species_traits, species_categories = NULL, all_traits = TRUE )
species_traits |
a |
species_categories |
(default = |
all_traits |
a logical (default = |
a ggplot2
object
fb_plot_species_traits_completeness(woodiv_traits)
fb_plot_species_traits_completeness(woodiv_traits)
Display a binary heatmap visualizing the species x traits matrix with colors
displaying present and missing traits. Traits are ordered from the most to
the least known (left to right).
Species are ordered from the ones with most to the ones with least traits
(bottom to top). The proportion of species with non-missing traits is shown
on the x-axis labels.
An additional column at the very right of the plot named "all_traits"
shows a summary considering if all other traits are known.
fb_plot_species_traits_missingness( species_traits, species_categories = NULL, all_traits = TRUE )
fb_plot_species_traits_missingness( species_traits, species_categories = NULL, all_traits = TRUE )
species_traits |
a |
species_categories |
2-columns |
all_traits |
a logical (default = |
a ggplot2
object
data(woodiv_traits) fb_plot_species_traits_missingness(woodiv_traits)
data(woodiv_traits) fb_plot_species_traits_missingness(woodiv_traits)
Display a figure of Present/Missing Trait Combinations where one square is represents one trait. The y-axis gives the frequency of the row (as well as its proportions compared to the total number of rows).
fb_plot_trait_combination_frequencies( species_traits, species_categories = NULL, order_by = c("number", "complete") )
fb_plot_trait_combination_frequencies( species_traits, species_categories = NULL, order_by = c("number", "complete") )
species_traits |
a |
species_categories |
(default = |
order_by |
|
a ggplot2
object
# Ordered by number by default fb_plot_trait_combination_frequencies(woodiv_traits) # Order by present traits fb_plot_trait_combination_frequencies(woodiv_traits, NULL, "complete")
# Ordered by number by default fb_plot_trait_combination_frequencies(woodiv_traits) # Order by present traits fb_plot_trait_combination_frequencies(woodiv_traits, NULL, "complete")
This functions outputs a ggplot2
figure that outputs a trait correlation
matrix. It only works on numerical traits and will output messages if
non-numerical traits are found and errors if no numerical traits are found.
Internally it uses the stats::cor()
function and only works on complete
observation (it removes any row that contains any NA
).
Use the ...
argument to pass options to the cor()
function.
fb_plot_trait_correlation(species_traits, species_categories = NULL, ...)
fb_plot_trait_correlation(species_traits, species_categories = NULL, ...)
species_traits |
a |
species_categories |
(default = |
... |
Additional options passed to |
a ggplot
object
fb_plot_trait_correlation(woodiv_traits) # Plot Spearman's correlation fb_plot_trait_correlation(woodiv_traits, method = "spearman")
fb_plot_trait_correlation(woodiv_traits) # Plot Spearman's correlation fb_plot_trait_correlation(woodiv_traits, method = "spearman")
This function outputs a data.frame
that summarises the species by trait
table to have many information in a glance. This can then return a data.frame
or a nicely formatted knitr::kable()
for inclusion in an Rmarkdown
document.
fb_table_trait_summary(species_traits, kable = FALSE)
fb_table_trait_summary(species_traits, kable = FALSE)
species_traits |
a |
kable |
|
a data.frame
with the following columns:
trait_name
: a character
column with the trait name as indicated in
species_traits
trait_type
: the nature of the trait (numeric
, categorical
,
or ordered
)
number_non_missing
: the total number of non-NA
trait values
proportion_non_missing
: the proportion of non-NA
trait values
trait_range
: for numerical traits, the range of values
trait_mean_sd
: for numerical traits, the mean plus-minus the standard
deviation
number_distinct
: for non-numerical traits, the number of categories
list_distinct
: for non-numerical traits, the list of categories
# Get a data.frame back fb_table_trait_summary(woodiv_traits) # Get a kable (to use in Rmd documents) fb_table_trait_summary(woodiv_traits, TRUE)
# Get a data.frame back fb_table_trait_summary(woodiv_traits) # Get a kable (to use in Rmd documents) fb_table_trait_summary(woodiv_traits, TRUE)
This dataset is derived from the WOODIV database (available at: https://www.nature.com/articles/s41597-021-00873-3). It contains information (classification, endemism, etc.) of the 24 Conifer tree species occurring in Portugal, Spain, France, and Italy (Mediterranean part). This information will be used as a species grouping factor.
This dataset shows the format of the argument species_categories
used in
several functions of funbiogeo
. Note that species names must be
the first column and must be named species
.
woodiv_categories
woodiv_categories
A data.frame
with 24 rows (species) and 6 columns (species
,
family
, genus
, binomial
, endemism
, and cultivated
).
Monnet AC, Cilleros K, Médail F et al. (2021) WOODIV, a database of occurrences, functional traits, and phylogenetic data for all Euro-Mediterranean trees. Scientific Data, 8, 89. DOI: 10.1038/s41597-021-00873-3
data("woodiv_categories") class(woodiv_categories) dim(woodiv_categories) woodiv_categories[1:6, ]
data("woodiv_categories") class(woodiv_categories) dim(woodiv_categories) woodiv_categories[1:6, ]
This dataset is derived from the WOODIV database (available at: https://www.nature.com/articles/s41597-021-00873-3). It contains the grid cells of sites (10 km x 10 km horizontal resolution) sampled in Portugal, Spain, France, and Italy (Mediterranean part) for which at least one of the 24 Conifer tree species occurs.
This dataset exemplifies the argument site_locations
used in
several functions of funbiogeo
. The variable site
corresponds to the
site labels (must match the same column in site_species
) and the variable
country
will be used as a site grouping factor.
woodiv_locations
woodiv_locations
An sf
POLYGON
object with 5,366 rows (grid cells) defined in the
ETRS89-extended / LAEA Europe Coordinate Reference System (EPSG:3035).
Monnet AC, Cilleros K, Médail F et al. (2021) WOODIV, a database of occurrences, functional traits, and phylogenetic data for all Euro-Mediterranean trees. Scientific Data, 8, 89. DOI: 10.1038/s41597-021-00873-3
data("woodiv_locations") class(woodiv_locations) dim(woodiv_locations) head(woodiv_locations)
data("woodiv_locations") class(woodiv_locations) dim(woodiv_locations) head(woodiv_locations)
This dataset is derived from the WOODIV database (available at:
https://www.nature.com/articles/s41597-021-00873-3). It contains the
presence/absence of the 24 Conifer tree species occurring in Portugal,
Spain, France, and Italy (Mediterranean part). The presence/absence is
available at 5,366 sites (grid cells of 10 x 10 km horizontal resolution).
Sites coordinates are provided in site_locations
.
This dataset shows the format of the argument site_species
used in
several functions of funbiogeo
. Note that site labels must be the first
column and must be named site
.
woodiv_site_species
woodiv_site_species
A data.frame
with 5,366 rows (sites) and 25 columns (1 column for
site label and 24 for species occurrence).
Monnet AC, Cilleros K, Médail F et al. (2021) WOODIV, a database of occurrences, functional traits, and phylogenetic data for all Euro-Mediterranean trees. Scientific Data, 8, 89. DOI: 10.1038/s41597-021-00873-3
data("woodiv_site_species") class(woodiv_site_species) dim(woodiv_site_species) woodiv_site_species[1:6, 1:6]
data("woodiv_site_species") class(woodiv_site_species) dim(woodiv_site_species) woodiv_site_species[1:6, 1:6]
This dataset is derived from the WOODIV database (available at: https://www.nature.com/articles/s41597-021-00873-3). It contains the values of four functional traits for 24 Conifer tree species occurring in Portugal, Spain, France, and Italy (Mediterranean part).
This dataset shows the format of the argument species_traits
used in
several functions of funbiogeo
. Note that species names must be
the first column and must be named species
.
woodiv_traits
woodiv_traits
A data.frame
with 24 rows (species) and the following five columns:
species name corresponding to the columns of site_species
adult plant height (in )
seed mass (in )
specific leaf area, i.e. the ratio between leaf area and dry
mass (in )
wood density, i.e. stem specific density
(in )
Monnet AC, Cilleros K, Médail F et al. (2021) WOODIV, a database of occurrences, functional traits, and phylogenetic data for all Euro-Mediterranean trees. Scientific Data, 8, 89. DOI: 10.1038/s41597-021-00873-3
data("woodiv_traits") class(woodiv_traits) dim(woodiv_traits) head(woodiv_traits)
data("woodiv_traits") class(woodiv_traits) dim(woodiv_traits) head(woodiv_traits)