4

so I am very new to R and I'm trying to plot a species accumulation curve for fish species collected from 3 separate habitats. Ideally, I would like to have one plot that shows 4 curves (one for all the fish in all habitats, and 3 for the fish in each habitat).

I have been struggling to find the correct code and I came across this question asked before . I tried to copy the code to work for my data, but can't seem to figure out what small bits I need to change to make it work.

What I have so far to create the curve for all collected fish is this:

AllFish = read.csv(file.choose(), header = TRUE)
AllFish_community = AllFish[2:74]

library(vegan)

Curve = specaccum(AllFish_community, method = "random", 
                  permutations = 100)

plot(Curve, ci = 0, ci.type = c("line"),
     ylab="Number of Species")

axis(1, at=1:15)

Which gives me a nice plot like this

I would like to know how I can code it, so that I get the 3 separate habitats added to the plot. I have my data arranged like this so that the first row is the label. There are 73 species of fish in the matrix, and 5 replicates of each of the 3 habitats.

Thank you.

Edit- Here is a link to my .csv data set

Etroyer
  • 43
  • 1
  • 4
  • Please share your sample data, not the screenshot. https://meta.stackoverflow.com/questions/315885/what-is-the-correct-way-to-share-r-data-on-stackoverflow – Tung Feb 13 '18 at 18:27
  • 1
    Sorry about that. It's in a .csv file. http://www.sharecsv.com/s/072e1a7894e6642e7a0834586c93ad05/nMDS_Data.csv – Etroyer Feb 13 '18 at 18:52
  • Can you update the link in your question as well? – Tung Feb 13 '18 at 18:54

1 Answers1

3

Your issue is that you are computing the species curve for all species. What you want (though I'm unsure if this is correct) is to compute separate curves for each habitat and then for all habitats, and finally plot everything together. Here is the code:

library(vegan)
library(dplyr)

AllFish = read.csv("FILELOCATION" , header = TRUE)
AllFish_community = AllFish[2:74]

curve_all = specaccum(AllFish_community, method = "random", 
                  permutations = 100)

#subset each habitat into its own df
AllFish %>% filter(Habitat == "Coral") -> coral
AllFish %>% filter(Habitat == "Rubble") -> rubble
AllFish %>% filter(Habitat == "Sand") -> sand

#calc species accumulation curve for each habitat
curve_coral = specaccum(coral[, 2:76], method = "random")
curve_rubble = specaccum(rubble[, 2:76], method = "random")
curve_sand = specaccum(sand[, 2:76], method = "random")

#plot curve_all first
plot(curve_all)
#then plot the rest
plot(curve_coral, add = TRUE, col = 2) #col is COLOUR setting, so change it to something else if you want
plot(curve_rubble, add = TRUE, col = 3)
plot(curve_sand, add = TRUE, col = 4)
kdarras
  • 389
  • 1
  • 5
  • 16
Amar
  • 1,340
  • 1
  • 8
  • 20
  • Select my post as an answer I want sweet sweet SO points. please :D – Amar Feb 15 '18 at 23:32
  • I don't believe that this is a correct answer. This allows separate plotting of each specaccum curve, but does not place them all together on a single, shared plot. – overcup Jun 21 '22 at 17:19
  • Use `mfrow` or `mfcol` to combine plots. It was marked correct by the asker, so I consider it correct. Feel free to post your own answer – Amar Jun 23 '22 at 00:29