Skip to content

Instantly share code, notes, and snippets.

@jslefche
jslefche / README.md
Last active May 29, 2022 00:23
ggplot2: theme_black()

Black theme for ggplot2

This is an additional theme for ggplot2 that generates an inverse black and white color scheme.

Example

ggplot(mtcars, aes(wt, mpg)) + geom_point()
# Add theme_black()
ggplot(mtcars, aes(wt, mpg)) + geom_point(color = "white") + theme_black()
@jslefche
jslefche / README.md
Last active August 12, 2019 14:54
Trichromatic equations

Calculation of chlorophyll concentration based on spectrophotometric equations

The function chlA uses the trichromatic equations to convert absorbance values (wavelengths, in nm) to estimates of chlorophyll concentration using the equations from:

Jeffrey, S. W., and G. F. Humphrey. 1975. New spectrophotometric equations for determining chlorophylls a, b, c1 and c2 in higher plants, algae and natural phytoplankton. Biochem Physiol Pflanz BPP:191–194.

The function takes a data.frame with the following values in the column names (corresponding to wavelengths in the equations in Jeffrey & Humphrey): "480", "510", "630", "647", "664", and "750." Additional arguments include extraction container volume (vol) and, optionally, area of extration (area, representing surface area for epiphytic algae).

The function returns the same data.frame with columns appending for chlorophyll-a, -b, and -c, and phaeopigment concentrations.

@jslefche
jslefche / README.md
Last active August 29, 2015 14:24
Coverage-based rarefaction

Estimating species richness using coverage-based rarefaction

This function uses the iNEXT package to approximate species richness for a given level of sample 'coverage' based on methods in:

Chao, Anne, and Lou Jost. "Coverage-based rarefaction and extrapolation: standardizing samples by completeness rather than size." Ecology 93.12 (2012): 2533-2547.

The function requires a data.frame or matrix with species as rows and communities as columns.

The function returns a data.frame with the observed richness, observed coverage (Chat), observed sample size (N), estimated richness (based on sample coverage), and optionally, richness based on the Chao1 estimator, and/or finally rarefied richness (individual-based subsampling).

@jslefche
jslefche / README.md
Last active September 13, 2017 18:12
Compute ultrametric trait matrix for functional traits

Computing ultrametric distance matrices from species' functional traits

fdist takes a functional trait matrix, and returns an ultrametric distance matrix using the method that best preserves the original (non-ultrametric) distances.

References:

Mouchet, M., Guilhaumon, F., Villéger, S., Mason, N. W., Tomasini, J. A., & Mouillot, D. (2008). Towards a consensus for calculating dendrogram‐based functional diversity indices. Oikos, 117(5), 794-800.

Mérigot, B., Durbec, J. P., & Gaertner, J. C. (2010). On goodness-of-fit measure for dendrogram-based analyses. Ecology, 91(6), 1850-1859.
@jslefche
jslefche / README.md
Last active August 29, 2015 14:18
ZEN_sites_map

Zostera Experimental Network Site Map

An interactive map showing site locations and images for the Zostera Experimental Network (ZEN).

Images from: http://www.zenscience.org/.

R code

# Load libraries
library(leaflet)
@jslefche
jslefche / README.md
Last active August 29, 2015 14:18
Multifunc_meta_map

Interactive Map

Map is created using supplementary dataset from:

Lefcheck et al. (2015) "Biodiversity enhances ecosystem multifunctionality across trophic levels and habitats." Nature Communications 6: 6936notep. http://dx.doi.org/10.1038/ncomms7936.

R Code

# Load libraries
#devtools::install_github("rstudio/leaflet", ref="feature/color-legend")
library(leaflet)
@jslefche
jslefche / dunnet.R
Last active December 31, 2015 03:49 — forked from jebyrnes/dunnet.R
###########
# Calculate a Dunnett's test
# using information from a meta-analysis
# using definitions at http://davidmlane.com/hyperstat/B112114.html
#
# Jarrett Byrnes & Jon Lefcheck
# 12/8/2013
###########
#helper functions