我目前正在进行一个项目,我需要知道从哪一天开始进行鸟类监测更方便/相关。为此,我想制作一条累积曲线,其中包含每个日期(x 轴)的累积物种数(y 轴)。我最初使用
specaccum
包中的 vegan
函数,就好像一个日期等于一个网站。虽然这项工作可以很好地概述我在现场需要的重复次数(或访问次数),但它没有为我提供我想知道的信息,以便我知道它与哪个日期更相关出去(因为时间方面对于鸟类的外观很重要)。
我还简单地记录了每个日期的物种数量,并用 ggplot
将其可视化,这给了我一个相当不错的概览,但我的主管想要一条累积曲线。
这是我的数据框的几行副本以及我到目前为止所做的事情:
数据为法语 Espèce = 物种
PDM<- data.frame(
Espèce= c("Corneille noire", "Alouette des champs", "Pipit farlouse", "Faisan de colchide", "Faisan de colchide", "Faisan de colchide",
"Pipit farlouse", "Pipit farlouse", "Alouette des champs", "Corneille noire", "Mésange charbonnière", "Merle noir",
"Étourneau sansonnet", "Pipit farlouse", "Pipit farlouse", "Alouette des champs", "Pipit farlouse", "Accenteur mouchet",
"Linotte mélodieuse", "Corneille noire", "Corbeau freux", "Alouette des champs", "Pinson des arbres", "Pipit farlouse",
"Merle noir", "Accenteur mouchet", "Mésange bleue", "Pigeon ramier", "Pigeon colombin", "Mésange charbonnière",
"Faisan de colchide", "Mouette rieuse", "Vanneau huppé", "Corneille noire", "Corneille noire", "Pigeon ramier",
"Pipit farlouse"),
Nombre= c(2, 5, 3, 1, 2, 1, 6, 6, 2, 3, 1, 1, 6, 6, 8, 1, 1, 1, 4, 2, 1, 7, 8, 3, 2, 6, 1, 1, 1, 4, 2, 1, 2, 3, 1, 4, 7, 2, 3, 1, 4, 7, 6, 5),
Date = c("04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022", "04/01/2022",
"21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022",
"21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022",
"21/01/2022", "21/01/2022", "21/01/2022", "21/01/2022"))
PDM <- PDM %>%
dplyr::select(Espèce, Date,Nombre) %>%
group_by(Date, Espèce) %>%
summarize(n = sum(Nombre))
PDM$Espèce <- as.factor(PDM$Espèce)
PDM <- PDM[!(PDM$Espèce %in% c("Lièvre variable", "Blaireau d'Europe","Lièvre d'Europe","Chat domestique","Chevreuil","Hermine","Lapin")),] # I removed mammals species, as I only study birds
PDM$Espèce <- droplevels(PDM$Espèce)
PDM <- PDM[order(as.Date(PDM$Date,format = "%d/%m/%Y")),]
PDM.w <- PDM %>% pivot_wider(names_from = "Espèce", values_from = "n",values_fill = 0)
PDM.w<- as.data.frame(PDM.w[,2:(ncol(PDM.w))])
PDM_courbe_2_ALL <- specaccum(PDM.w)
PDM_courbe_2_ALL
plot(PDM_courbe_2_ALL, col = "blue",ci.type = "poly", ci.col = "lightblue", ci.lty = 0, ylab = "Nombre of species",xlab = "Nomber of visits", main = "Accumulation curves Site1", font.sub = 4)
这里是 ggplot :
PDM <- PDM %>%
group_by(Date) %>%
summarise(n_sp = length(Espèce))
ggplot(PDM_sp) + aes(x= Date, y = n_sp) +geom_point() + geom_smooth(fill = "lightblue") + theme_classic() + ylab("Number of species")+geom_label_repel(aes(label = as.character(Date)),
box.padding = 0.35,
point.padding = 0.7,
segment.color = 'black')+ labs(title = "Number of species through time", subtitle = "Site1")
这就是我正在寻找的: 这看起来很简单,但由于某些原因,我很难弄清楚如何计算每个日期的new物种的数量(以便之后累积每个数字)。我非常感谢您的反馈。
有很多方法,但是既然您使用了
vegan::specaccum
,您也可以使用它来通过参数以任意顺序添加采样单位method="collector"
这应该有效(未经测试,甚至没有您的数据):
i <- order(PDM$Date)
specaccum(PDM[i, ], method = "collector") # order PDM by Date and collect