繁体   English   中英

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

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

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

我一直在苦苦寻找正确的代码,我碰到这个问题问出来之前 我试图复制代码以便为我的数据工作,但似乎无法弄清楚我需要改变哪些小部分才能使其工作。

到目前为止,我为所有收集的鱼创建曲线的是:

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)

这给了我一个很好的情节像这样

我想知道我如何编码它,以便我将3个独立的栖息地添加到情节中。 我已经安排像我的数据使得第一行是标签。 基质中有73种鱼类,3种栖息地各有5种重复。

谢谢。

编辑 - 是我的.csv数据集的链接

您的问题是您正在计算所有物种的物种曲线。 你想要的是什么(虽然我不确定这是否正确)是为每个栖息地计算单独的曲线,然后为所有栖息地计算,最后将所有的一起绘制。 这是代码:

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