Search code examples
rformattingdataframevegan

Creating a species Accumulation Curve with different format


I am currently working on a dataframe which looks like this:

    data.frame(Plot_ID=c(1,1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4),
               Species=c("a","a","a","b","b","c","c","b","b","b","b","d","d","d","e","e","e","e","a","a","a")
               DBH=c(12,32,44,11,14,66,43,22,88,22,23,45,354,6,7,45,12,11,5,6,8))

DBH is just the diameter of the species. What I want to create is a species accumulation curve, however the packet specaccum only allows for a different format which is like this:

data.frame (Spec1=c(1,0,2,3),Spec2=c(0,0,0,4),Spec3=c(1,1,2,3))

My data has over 3000 rows, with more that a hundred species which makes it very difficult to reformat the data accordingly. Is there a way to easily reformat the data, or to use the data like it is with a different package?


Solution

  • Ok after a while I remembered the pivot-table of LibreOffice, where you can exactly format the data to have the species in columns, each plot in a row and the sum in between.

    For that, create a 3rd column which includes only the number 1, your data should look like this:

    d1<-data.frame(Plot_ID=c(1,1,2,2,3,3), 
                   Species=c("a","b","a","c","d","c"), 
                   Count=c(1,1,1,1,1,1))
    

    Export the data frame as .csv file using

    write.table(d1, "~/path/of/desire/d1.csv")
    

    Import the csv. table in Libreoffice by using space as separator. Delete the first column as it is the internal R-ID and shifts the headings.

    Mark your data and go to Data->Pivot-table, select marked data and click OK.

    You will see something like this enter image description here

    Loai.cay is the Species here. Drag the Species to the column-cields, the Plot_ID to the row-fields and the Count to the data-fields, as it is the case in the picture. Press OK and copy the result in a extra table. Press CTRL+SHIFT+S and select save as .csv file. Import the csv-file in R and use the specaccum function as described in the description of the function.

    Hope this helps someone else than me.