如何绘制按日期的鸟类物种累积曲线以确定最佳监测日期
鸟类监测适宜日期:日期-累积物种数曲线绘制问题
问题背景
我需要确定开展鸟类监测的适宜日期,希望绘制以日期为X轴、累积物种数量为Y轴的累积曲线。最初使用vegan包的specaccum()函数,将每个日期视为一个样点,该方法虽能了解野外调查所需的重复次数,但无法体现鸟类出现的时间特性,无法确定最佳外出监测日期。曾提取单日物种数量并使用ggplot()可视化,但导师要求绘制累积曲线。
数据样例及现有代码
数据构造
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"))
数据处理与specaccum()绘图代码
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")),] # 移除哺乳类,仅保留鸟类 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")
期望效果
期望得到类似附图(红色曲线样式)的日期-累积物种数曲线,能直观展示随时间推移的物种累积情况,从而确定适宜的监测日期。
解决方案:绘制时间序列累积物种数曲线
步骤1:计算累积物种数
在数据处理后,按日期排序,逐步统计到每个日期为止的累计物种总数:
library(dplyr) library(lubridate) library(purrr) # 转换日期格式并排序 PDM_clean <- PDM %>% mutate(Date = dmy(Date)) %>% arrange(Date) # 统计每个日期的物种,然后计算累积物种数 cumulative_sp <- PDM_clean %>% group_by(Date) %>% summarise(species = list(Espèce)) %>% mutate(cumulative_species = accumulate(species, union)) %>% mutate(cumulative_count = map_int(cumulative_species, length))
步骤2:用ggplot绘制累积曲线
library(ggplot2) library(ggrepel) ggplot(cumulative_sp, aes(x = Date, y = cumulative_count)) + geom_line(color = "red", size = 1.2) + geom_point(size = 3) + geom_label_repel(aes(label = Date), box.padding = 0.35, point.padding = 0.7) + theme_classic() + labs(x = "监测日期", y = "累积物种数量", title = "鸟类监测累积物种数随时间变化", subtitle = "Site1")
这段代码会生成以日期为横轴、累积物种数为纵轴的红色曲线,清晰展示不同日期的物种累积情况,帮你判断新增物种最多的时段,确定适宜监测日期。
内容的提问来源于stack exchange,提问作者Wonderia
相关产品推荐
相关产品推荐

