rplotvegan

accumulation curve in R


I have data of species at 4 sites over several months. I have successfully created accumulation graphs using package vegan in R but I would like to plot all 4 sites on one graph.

At first I had a data sheet with all sites and months but the when I plotted specaccum the result was a curve of accumulation of all data regardless of site.

Because of this I split each site into a separate data sheet which I loaded into R. In each data sheet the first row is species names and each additional row below that is a month.

For example I loaded the data of one of my sites "FMR". Then I did the following:

FMR <-specaccum(FMRJ2F, "random")
plot(FMR)

I did the same for my other sites, PP, DUX, PM. How can i put all 4 lines on one plot?


Solution

  • You can just use the add=TRUE argument in plot.specaccum().

    library(vegan)
    data(BCI) 
    l <- lapply(c(1,21,41,61,81), \(i) specaccum(BCI[, seq(i,i+19)], method="random"))
    plot(l[[1]])
    for (i in 2:5) plot(l[[i]], add=TRUE, col=i)
    

    This code snippet just loads the built-in BSI dataset from {vegan}, and creates a list l of 5 specaccum objects by running specaccum() on a subset of the columns in BCI. You don't need to do this since you already have the specaccum objects.

    Then, we create the first plot, and add, with each iteration of the for-loop, a new curve with add=TRUE.