簡體   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