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] , Matthias Grenié [aut] |
Maintainer: | Nicolas Casajus <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.0.9000 |
Built: | 2024-11-22 05:08:22 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
.
library("funbiogeo") data("site_locations") data("site_species") ## 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(site_locations, site_species[, 1:4], tavg, fun = sum)
library("funbiogeo") data("site_locations") data("site_species") ## 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(site_locations, 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.
library("funbiogeo") data("site_species") site_coverage_by_species <- fb_count_sites_by_species(site_species) head(site_coverage_by_species)
library("funbiogeo") data("site_species") site_coverage_by_species <- fb_count_sites_by_species(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.
library("funbiogeo") data("site_species") species_coverage_by_site <- fb_count_species_by_site(site_species) head(species_coverage_by_site)
library("funbiogeo") data("site_species") species_coverage_by_site <- fb_count_species_by_site(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.
library("funbiogeo") data("species_traits") species_coverage_by_trait <- fb_count_species_by_trait(species_traits) head(species_coverage_by_trait)
library("funbiogeo") data("species_traits") species_coverage_by_trait <- fb_count_species_by_trait(species_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.
library("funbiogeo") data("species_traits") trait_coverage_by_species <- fb_count_traits_by_species(species_traits) head(trait_coverage_by_species)
library("funbiogeo") data("species_traits") trait_coverage_by_species <- fb_count_traits_by_species(species_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.
library("funbiogeo") data("site_species") data("species_traits") site_cwm <- fb_cwm(head(site_species), species_traits) head(site_cwm)
library("funbiogeo") data("site_species") data("species_traits") site_cwm <- fb_cwm(head(site_species), species_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.
library("funbiogeo") data("site_species") # Get sites with more than 40% of the species new_site_species <- fb_filter_sites_by_species_coverage( site_species, threshold_species_proportion = 0.4 ) # There are now only 148 sites dim(new_site_species) new_site_species[1:3, 1:4]
library("funbiogeo") data("site_species") # Get sites with more than 40% of the species new_site_species <- fb_filter_sites_by_species_coverage( 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.
library("funbiogeo") data("site_species") data("species_traits") # Filter all the sites where all species have known traits new_site_species <- fb_filter_sites_by_trait_coverage( site_species, species_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( site_species, species_traits, threshold_traits_proportion = 0.8 ) # There are now four sites nrow(new_site_species_2)
library("funbiogeo") data("site_species") data("species_traits") # Filter all the sites where all species have known traits new_site_species <- fb_filter_sites_by_trait_coverage( site_species, species_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( site_species, species_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
.
library("funbiogeo") data("site_species") # Filter species present in at least 10% of the sites new_site_species <- fb_filter_species_by_site_coverage( 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)
library("funbiogeo") data("site_species") # Filter species present in at least 10% of the sites new_site_species <- fb_filter_species_by_site_coverage( 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.
library("funbiogeo") data("species_traits") # Filter species that have at least 60% of the traits described new_species_traits <- fb_filter_species_by_trait_coverage( species_traits, threshold_traits_proportion = 0.6 ) # There are now only 93 species nrow(new_species_traits)
library("funbiogeo") data("species_traits") # Filter species that have at least 60% of the traits described new_species_traits <- fb_filter_species_by_trait_coverage( species_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.
library("funbiogeo") data("species_traits") # Filter traits that have at least 60% non-missing values new_species_traits <- fb_filter_traits_by_species_coverage( species_traits, threshold_species_proportion = 0.6 ) # There are now only 2 traits ncol(new_species_traits)
library("funbiogeo") data("species_traits") # Filter traits that have at least 60% non-missing values new_species_traits <- fb_filter_traits_by_species_coverage( species_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.
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_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)
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_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.
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_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]
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_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).
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_data.csv", package = "funbiogeo") all_data <- read.csv(filename) head(all_data) species_categories <- fb_format_species_categories(all_data, "species", "order") species_categories[1:6, ]
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_data.csv", package = "funbiogeo") all_data <- read.csv(filename) head(all_data) species_categories <- fb_format_species_categories(all_data, "species", "order") 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.
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_data.csv", package = "funbiogeo") all_data <- read.csv(filename) head(all_data) traits <- c("adult_body_mass", "gestation_length", "litter_size", "max_longevity", "sexual_maturity_age", "diet_breadth") species_traits <- fb_format_species_traits(all_data, "species", traits) head(species_traits)
library("funbiogeo") filename <- system.file("extdata", "raw_mammals_data.csv", package = "funbiogeo") all_data <- read.csv(filename) head(all_data) traits <- c("adult_body_mass", "gestation_length", "litter_size", "max_longevity", "sexual_maturity_age", "diet_breadth") 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( site_species, species_traits ) head(site_trait_cov)
site_trait_cov <- fb_get_all_trait_coverages_by_site( site_species, species_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.
library("funbiogeo") data("site_locations") ## 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(site_locations), layers)
library("funbiogeo") data("site_locations") ## 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(site_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( site_species, species_traits ) # Get only combinations of 3 traits three_traits = fb_get_trait_combination_coverage( site_species, species_traits, 3 ) # Combinations of 2, 3, and 4 traits two_to_four = fb_get_trait_combination_coverage( site_species, species_traits, c(2, 3, 4) )
# Compute Coverages using All Trait Combinations all_combinations = fb_get_trait_combination_coverage( site_species, species_traits ) # Get only combinations of 3 traits three_traits = fb_get_trait_combination_coverage( site_species, species_traits, 3 ) # Combinations of 2, 3, and 4 traits two_to_four = fb_get_trait_combination_coverage( site_species, species_traits, c(2, 3, 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.
library("funbiogeo") data("site_species") data("species_traits") site_trait_cov <- fb_get_trait_coverage_by_site(site_species, species_traits) head(site_trait_cov)
library("funbiogeo") data("site_species") data("species_traits") site_trait_cov <- fb_get_trait_coverage_by_site(site_species, species_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() # Load data data("species_traits") data("site_species") data("site_locations") # Create report fb_make_report( path = temp_path, author = "Casajus N. and Grenié M.", species_traits_name = "species_traits", site_species_name = "site_species", site_locations_name = "site_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() # Load data data("species_traits") data("site_species") data("site_locations") # Create report fb_make_report( path = temp_path, author = "Casajus N. and Grenié M.", species_traits_name = "species_traits", site_species_name = "site_species", site_locations_name = "site_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(site_species) # Map of Species Richness rich_map <- fb_map_site_data(site_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(site_species) # Map of Species Richness rich_map <- fb_map_site_data(site_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(site_locations, site_species, species_traits)
fb_map_site_traits_completeness(site_locations, site_species, species_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(site_species, species_traits)
fb_plot_distribution_site_trait_coverage(site_species, species_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(site_species) # Add a vertical cutoff line (40% of sites) fb_plot_number_sites_by_species(site_species, 0.4)
fb_plot_number_sites_by_species(site_species) # Add a vertical cutoff line (40% of sites) fb_plot_number_sites_by_species(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
data(species_traits) fb_plot_number_species_by_trait(species_traits) # Add a vertical cutoff line (12.5% of species) fb_plot_number_species_by_trait(species_traits, NULL, 1/8)
data(species_traits) fb_plot_number_species_by_trait(species_traits) # Add a vertical cutoff line (12.5% of species) fb_plot_number_species_by_trait(species_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
data(species_traits) fb_plot_number_traits_by_species(species_traits) # Add a vertical cutoff line (33% of the species) fb_plot_number_traits_by_species( species_traits, threshold_species_proportion = 1/3 )
data(species_traits) fb_plot_number_traits_by_species(species_traits) # Add a vertical cutoff line (33% of the species) fb_plot_number_traits_by_species( species_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
data("site_locations") # 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(site_locations), layers)
data("site_locations") # 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(site_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(site_species, species_traits)
fb_plot_site_traits_completeness(site_species, species_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
data(species_traits) fb_plot_species_traits_completeness(species_traits)
data(species_traits) fb_plot_species_traits_completeness(species_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(species_traits) fb_plot_species_traits_missingness(species_traits)
data(species_traits) fb_plot_species_traits_missingness(species_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(species_traits) # Order by present traits fb_plot_trait_combination_frequencies(species_traits, NULL, "complete")
# Ordered by number by default fb_plot_trait_combination_frequencies(species_traits) # Order by present traits fb_plot_trait_combination_frequencies(species_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(species_traits) # Plot Spearman's correlation fb_plot_trait_correlation(species_traits, method = "spearman")
fb_plot_trait_correlation(species_traits) # Plot Spearman's correlation fb_plot_trait_correlation(species_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(species_traits) # Get a kable (to use in Rmd documents) fb_table_trait_summary(species_traits, TRUE)
# Get a data.frame back fb_table_trait_summary(species_traits) # Get a kable (to use in Rmd documents) fb_table_trait_summary(species_traits, TRUE)
This dataset contains spatial coordinates (grid cells of 0.5° x 0.5°
horizontal resolution) of sites of Western Europe where mammals species
presence/absence (see site_species
dataset) has been sampled.
site_locations
site_locations
An sf
object with 1,505 rows (grid cells) with a WGS84 (EPSG:4236)
Coordinate Reference System.
See https://github.com/frbcesab/eumammals for a complete description of the workflow used to create this dataset.
This dataset shows the format of the argument site_locations
used in
several functions of funbiogeo
.
The variable site
corresponds to the sites labels.
data("site_locations") class(site_locations) dim(site_locations) head(site_locations)
data("site_locations") class(site_locations) dim(site_locations) head(site_locations)
This dataset contains the presence/absence of mammals species in Western Europe. This dataset is derived from IUCN range maps downloaded at: https://www.iucnredlist.org/resources/spatial-data-download. In respect to the license, species names have been anonymized.
site_species
site_species
A data.frame
with 1,505 rows (sites) and 150 columns (1 column for
site label and 149 for species occurrence).
See https://github.com/frbcesab/eumammals for a complete description of the workflow used to create this dataset.
This dataset shows the format of the argument site_species
used in
several functions of funbiogeo
.
Note that sites labels (site
) is the first column of this dataset.
IUCN (2021) The IUCN Red List of Threatened Species. Version 2021-2. Downloaded on 2021/10/11.
data("site_species") class(site_species) dim(site_species) site_species[1:6, 1:6]
data("site_species") class(site_species) dim(site_species) site_species[1:6, 1:6]
This dataset contains the order of mammals species in Western Europe. This dataset is derived from IUCN range maps downloaded at: https://www.iucnredlist.org/resources/spatial-data-download. In respect to the license, species names have been anonymized.
species_categories
species_categories
A data.frame
with 149 rows (species) and 2 columns (1 column for
species name and 1 for the order).
See https://github.com/frbcesab/eumammals for a complete description of the workflow used to create this dataset.
This dataset shows the format of the argument species_categories
used in
several functions of funbiogeo
.
Note that species names (species
) is the first column of this dataset.
IUCN (2021) The IUCN Red List of Threatened Species. Version 2021-2. Downloaded on 2021/10/11.
data("species_categories") class(species_categories) dim(species_categories) species_categories[1:6, ]
data("species_categories") class(species_categories) dim(species_categories) species_categories[1:6, ]
This dataset contains values for six functional traits of Western Europe mammals species. These values were extracted from the PanTHERIA database (Jones 2009), a database on World mammals traits available at: https://esapubs.org/archive/ecol/E090/184/metadata.htm. In respect to the IUCN license, species names have been anonymized.
species_traits
species_traits
A matrix with 149 rows (species) and the following seven columns:
species name corresponding to the columns of site_species
adult body mass (in grams)
length of time of non-inactive fetal growth (in days)
number of offspring born per litter per female
maximum adult age (in months)
age when individuals are first physically capable of reproducing (in days)
number of dietary categories eaten
See https://github.com/frbcesab/eumammals for a complete description of the workflow used to create this dataset.
This dataset shows the format of the argument species_traits
used in
several functions of funbiogeo
.
Note that species names (species
) is the first column of this dataset.
Jones KE et al. (2009) PanTHERIA: A species-level database of life history, ecology, and geography of extant and recently extinct mammals. Ecology, 90, 2648. DOI: 10.1890/08-1494.1.
data("species_traits") class(species_traits) dim(species_traits) head(species_traits)
data("species_traits") class(species_traits) dim(species_traits) head(species_traits)