简体   繁体   English

如何使用R在一个图中绘制多种物种积累曲线

[英]How to plot multiple species accumulation curves in one plot using R

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. 所以我对R很新,我试图绘制从3个不同栖息地收集的鱼类的物种积累曲线。 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). 理想情况下,我想有一个图表显示4条曲线(一条适用于所有栖息地的所有鱼类,另外一条适用于每个栖息地的鱼类)。

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. 我想知道我如何编码它,以便我将3个独立的栖息地添加到情节中。 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. 基质中有73种鱼类,3种栖息地各有5种重复。

Thank you. 谢谢。

Edit- Here is a link to my .csv data set 编辑 - 是我的.csv数据集的链接

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM