【问题标题】:How to plot multiple species accumulation curves in one plot using R如何使用 R 在一个图中绘制多个物种积累曲线
【发布时间】:2018-02-13 16:42:01
【问题描述】:

所以我对 R 非常陌生,我正在尝试绘制从 3 个不同栖息地收集的鱼类物种的物种积累曲线。理想情况下,我想要一个显示 4 条曲线的图(一条用于所有栖息地中的所有鱼,3 条用于每个栖息地中的鱼)。

我一直在努力寻找正确的代码,我遇到了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 数据集的链接

【问题讨论】:

标签: r plot


【解决方案1】:

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

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)

【讨论】:

  • 选择我的帖子作为答案我想要甜甜的 SO 积分。请:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-17
  • 2021-06-02
  • 1970-01-01
  • 1970-01-01
  • 2021-05-04
  • 2021-05-22
  • 1970-01-01
相关资源
最近更新 更多