所以我对R很新,我试图绘制从3个不同栖息地收集的鱼类的物种积累曲线。理想情况下,我希望有一个图表显示4条曲线(一条适用于所有栖息地的所有鱼类,另外一条适用于每个栖息地的鱼类)。
我一直在努力寻找正确的代码,我遇到了问题before 。我试图复制代码以便为我的数据工作,但似乎无法弄清楚我需要改变哪些小部分才能使其工作。
到目前为止,我为所有收集的鱼创建曲线的是:
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)
这给了我一个很好的情节,如this
我想知道如何编码,以便我将3个独立的栖息地添加到情节中。我的数据排列方式为this,因此第一行是标签。基质中有73种鱼类,3种栖息地各有5种重复。
谢谢。
编辑 - Here是我的.csv数据集的链接
答案 0 :(得分:3)
您的问题是您正在计算所有物种的物种曲线。你想要的是什么(虽然我不确定这是否正确)是为每个栖息地计算单独的曲线,然后为所有栖息地计算,最后将所有的一起绘制出来。这是代码:
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)