first, load your libraries! We’ll be using a new one this time called vegan, so make sure you also INSTALL that package first.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.0     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.2     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(vegan)
## Loading required package: permute

Ecological packages like vegan require data in a wide Sample \(\times\) Taxon matrix format rather than a long spreadsheet, so make sure that your data is formatted correctly (as show in the lab handout)

Load your .csv file with the class’s data. You’ll be loading two files, make sure they have clear names so you know what files are what!

In this example, I’m using simulated data - you’ll use your own data and replace whatever you call it with the dataframe community_matrix in the code below.

We’ll use the function specaccum() with method = “random” to average across 100 random sample orderings.

Species accumulation curve data:

sac <- specaccum(community_matrix, method = "random", permutations = 100)

sac_df <- tibble(
  Samples = sac$sites,
  Richness = sac$richness,
  SD = sac$sd
)

Now let’s visualize our data!

ggplot(sac_df, aes(x = Samples, y = Richness)) +
  # 95% confidence ribbon (+/- 1.96 SD)
  geom_ribbon(
    aes(ymin = pmax(0, Richness - 1.96 * SD), ymax = Richness + 1.96 * SD),
    alpha = 0.25
  ) +
  # Main accumulation line and points
  geom_line() +
  geom_point() +

  scale_x_continuous() +
  labs(
    title = "Fossil Locality Species Accumulation Curve",
    subtitle = "Shaded area represents 95% confidence interval across 100 random sample orderings",
    x = "Number of Samples Collected",
    y = "Cumulative Number of Taxa (Richness)"
  ) +
  theme_minimal(base_size = 13)