knitr::opts_chunk$set(echo = TRUE)
Install the package.
devtools::install_github("elisabethpigott/pigott.package")
Load the package. The tutorial R Markdown can be found in vignettes.
library(pigott.package)
This function will convert a species community dataframe and transform it into a matrix. You can then use this matrix to plug into community analysis functions. You must use a dataframe with only Species, Site_names, and Count or Abundance in three separate columns. For my example data, formal site names are irrelevant, so I use Mo_since_burn_grouped instead of Site_names as my independent variable. The output will be a matrix of spread out species community data with Species in rows and Sites in columns.
library(tidyverse) bees <- read_csv("../inst/extdata/bee_fxndata.csv") print(bees) bmatrix <- beematrix(bees, Species, Mo_since_burn_grouped, Count)
Check to see how your matrix looks:
head(bmatrix)
This function uses iNEXT to report the effective number of species as Hill numbers of the order q. There are three diversity orders (0-2) of q: richness, Shannon diversity, and Simpson diversity. The function requires a matrix as the input argument and the output will be a ggplot showing species diversity across the number of individuals caught. This is important to see, as I am collecting species at sites with different burn histories to see if there is an effect of time since burn on bee communities.
We will be analyzing Shannon diversity (q = 1) using the shannon function:
library(iNEXT) shannonplot <- shannon(bmatrix, q = 1, datatype = "abundance") shannonplot
The other two functions, richness and Simpson, can also be analyzed, but we will not be executing the code during this presentation. I will drop the code below if you want to look at the richness and Simpson plots yourself.
library(iNEXT) richnessplot <- richness(bmatrix, q = 0, datatype = "abundance") richnessplot
library(iNEXT) simpsonplot <- simpson(bmatrix, q = 2, datatype = "abundance") simpsonplot
This function uses metaMDS to perform an NMDS ordination on a community dataset. Nonmetric multidimensional scaling is typically used in community ecology to iteratively find dissimilarity relations between samples among all sites sampled at. For my community dataset, this function will show me if my sites are dissimilar from one another by the relative abundances and species richness I collected from each site. The input must be a data frame with the community data spread out with species as columns and sites as rows.
First, we need to transpose my original matrix so that species are in columns and sites are in rows. Then, we need to formally convert the matrix into a data frame. For whatever reason, metaMDS and iNEXT have opposite input matrix formats.
transbmatrix <- t(bmatrix) transbmatrix <- as.data.frame(transbmatrix)
Now I can compute my function.
library(vegan) bee.mds <- nmdsplot(transbmatrix, distance = "bray", autotransform = "FALSE") bee.mds
These data show that sites burned 6 to 10 months ago are more similar to sites burned 21 plus months ago. Sites burned 0 to 5 months ago have little species richness. My species checklist is still a work in progress, however.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.