生态位宽度是指物种(或其它生物单位)在群落中所利用的各种不同资源的总和。
物种的生态位越宽,该物种的特化程度就越小,倾向于泛化种(generalist species);物种的生态位越窄,倾向于是一个特化种(specialists species)。
本篇所使用为生态位宽度指数即**Levins的生态位宽度指数。**
(除此之外也有用shannon指数)
# 安装并加载必要的包
if (!requireNamespace("readxl", quietly = TRUE)) {
install.packages("readxl")
}
if (!requireNamespace("spaa", quietly = TRUE)) {
install.packages("spaa")
}
if (!requireNamespace("ggplot2", quietly = TRUE)) {
install.packages("ggplot2")
}
library(readxl)
library(spaa)
library(ggplot2)
# 读取Excel文件
file_path <- "D:/你的路径/totalGenus.xlsx"
sheets <- excel_sheets(file_path)
# 函数用于计算Levins生态位宽度
levins_niche_width <- function(series) {
proportions <- series / sum(series)
niche_width <- 1 / sum(proportions ^ 2)
return(niche_width)
}
# 遍历每个工作表
for (sheet_name in sheets)