Search code examples
rcurvevegan

Standard deviation is 0 in the accumulation curve of the “vegan” package


dados <- structure(list(Anos = c(2009L, 2015L, 2011L, 2007L, 2005L, 2013L
  ), Coluna1 = c(13L, 11L, 9L, 8L, 6L, 6L), Coluna2 = c(1L, 0L, 
  0L, 1L, 0L, 0L), Coluna3 = c(1L, 8L, 10L, 2L, 4L, 4L), Coluna4 = c(7L, 
  5L, 2L, 5L, 7L, 1L)), class = "data.frame", row.names = c(NA, 
  -6L))

library(vegan)

resultado <- specaccum(dados)

> Warning message:
In cor(x > 0): standard deviation is zero    

richness <- resultado$richness
sd <- resultado$sd
sites <- resultado$sites

y.mínimo <- min(richness)
y.máximo <- max(richness)

y.baixo <- y.mínimo*0.80
y.alto <- y.máximo+(y.mínimo*0.10)

limites.y <- c(y.baixo, y.alto)
plot(riqueza ~ amostras, type = "l",
 ylim = limites.y, xlim = c(1, 9), las = 1, xlab = "Esforço amostral",
 ylab = "Riqueza de espécies")

arrows(amostras, riqueza-desvio, amostras, riqueza+desvio,
 angle = 90, code = 3, length = 0.05)

points(riqueza ~ amostras, pch = 21, bg = "white")

The graph is this: https://i.sstatic.net/Y42TS.jpg

Would anyone know how do I fix my data (or codes), so that the graph looks more or less as it is below? https://i.sstatic.net/UiD8T.jpg


Solution

  • Here is simple way of constructing the desired plot with your data. If you wish to build a nicer plot I would suggest looking into the iNEXT package.

    library(vegan)
    
    #Convert data frame to matrix
    dados_matrix<-as.matrix(dados[,-1])
    #Name rows as the first column in original df
    row.names(dados_matrix)<-dados[,1]
    
    #Do the specaccum function
    resultado <- specaccum(dados_matrix)
    
    #Plot
    plot(resultado,
         xlab = "Esforço amostral",
         ylab = "Riqueza de espécies",
         #Multiplier to calculate confidence intervals based on sd
         #In this example error bars are calculated as the mean +/- 1.96 sd
         ci = 1.96,
         #Type of confidence intervals
         ci.type = "bar",
         #Length of error bars (i.e., horizontal lines)
         ci.length = 0.1,
         #line width
         lwd = 1.8)
    

    plot specaccum