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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With