Accumulation curve in R

I have data on species at 4 sites for several months. I have successfully created accumulation graphs using the package veganin R, but I would like to build all 4 sites on one graph.

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

Because of this, I split each site into a separate data sheet, which I downloaded in R. In each data sheet, the first row is the names of the species, and each additional row is lower than a month.

For example, I uploaded data from one of my FMR sites. Then I did the following:

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

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

+3
source share
2 answers

You can just use the argument add=Tinplot.specaccum(...)

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

This piece of code simply loads the built-in BSI dataset into veganand creates a list of 5 specaccumobjects, running specaccum(...)in a subset of the columns in the BCI. You do not need this, since you already have specaccum objects.

Then we create the first graph and add each new curve c add=T.

+5
source

, @jlhoward, , . , , , . , add.

:

library(vegan)
data(BCI)
sp1 <- specaccum(BCI, 'random')

# random modification to BCI data to create data for a second curve
BCI2 <- as.matrix(BCI)
BCI2[sample(prod(dim(BCI2)), 10000)] <- 0
sp2 <- specaccum(BCI2, 'random')

# Combine the specaccum objects into a list 
l <- list(sp1, sp2) 

# Calculate required y-axis limits
ylm <- range(sapply(l, '[[', 'richness') + 
           sapply(l, '[[', 'sd') * c(-2, 2))

# Apply a plotting function over the indices of the list
sapply(seq_along(l), function(i) {
  if (i==1) { # If it the first list element, use plot()
    with(l[[i]], {
      plot(sites, richness, type='l', ylim=ylm, 
           xlab='Sites', ylab='random', las=1)
      segments(seq_len(max(sites)), y0=richness - 2*sd, 
               y1=richness + 2*sd)
    })    
  } else {
    with(l[[i]], { # for subsequent elements, use lines()
      lines(sites, richness, col=i)
      segments(seq_len(max(sites)), y0=richness - 2*sd, 
               y1=richness + 2*sd, col=i)
    })     
  }
})

legend('bottomright', c('Site 1', 'Site 2'), col=1:2, lty=1, 
       bty='n', inset=0.025)

enter image description here

+1

All Articles