Search code examples
rcurvevegan

How to plot rarefaction curves in R using Vegan?


I have a dataset containing genes identified in different reference genomes. So, the reference genomes are in the Rows and the genes are in the columns of the table. The table is coded as a binary where 0 means the gene is absent and 1 means the gene is present. I made gene accumulation curves, which indicates that the number of genes per genomes is approaching a plateau. Now, I am trying to plot the rarefaction curves using the R-package vegan. I used the following codes:

b<-read.csv("data.csv", header = T, check.names = F)
S <- specnumber(b) # observed number of species
(raremax <- min(rowSums(b)))
Srare <- rarefy(b, raremax)
plot(Srare, xlab = "Observed No. of genes", ylab = "Rarefied No. of genes")
abline(0, 1)
rarecurve(b, step = 15, sample = raremax, col = "blue", cex = 0.6)

The data set is like the following:

          gene1 gene2 gene3
#genome1    0     1     0
#genome2    1     0     1
#genome3    1     0     1

However, using this code I am not getting any satisfactory output. I just get only one straight line through the diagonal. I have attached the output below. rarefaction curve

Can someone please suggest me how can I correct the output?

Thank you.


Solution

  • rarefy function rarefies individual rows of your data: it takes a subsample of your occurrences ("individuals") within each row. If all these sampled individuals have value 1, you will have a subsample of ones, and the sum of ones is the sample size: that was what you got. There is no meaningful way of rarefying a vector of ones: you need count data with some counts > 1.

    You were perhaps looking for accumulation of genes in your whole data set when subsampling rows of the matrix. This is done in vegan function specaccum (argument method = "exact") which has its own plot etc methods.