划分方法
示例数据
计算代码
在开始计算前,我们需要先设置好路径,并将示例数据放到路径下。
# 设置路径
setwd("...")
getwd()
# 导入相应的R包
library(adiv)
library(ggtern)
# 导入数据
grazed_data <- read.csv("Species_abundances_and_functional_traits_in_grazed_plots.csv")
ungrazed_data <- read.csv("Species_abundances_and_functional_traits_in_ungrazed_plots.csv")
# 查看数据结构
head(grazed_data)
## Species G1 G2 G3 G4 G5 G6 G7 G8 SLA LDMC N C
## 1 Acer monspessulanum 0.0 0.5 0 0 1 0 0.0 0.0 0.134 0.906 0.471 0.808
## 2 Acinos arvensis 0.5 2.0 1 0 0 16 28.0 0.5 0.074 0.511 0.082 0.745
## 3 Arrhenatherum elatius 0.0 1.0 0 0 0 0 0.0 0.0 0.683 0.503 0.659 0.580
## 4 Bromus erectus 10.0 11.0 17 32 9 11 7.0 9.0 0.299 0.587 0.403 0.547
## 5 Bromus sterilis 0.0 0.5 0 0 0 0 0.0 1.0 0.959 0.237 0.666 0.644
## 6 Bupleurum baldense** 1.0 1.0 0 0 0 0 0.0 0.0 0.394 0.535 0.109 0.463
head(ungrazed_data)
## Species N1 N2 N3 N4 N5 N6 N7 SLA LDMC N C
## 1 Acer monspessulanum 60.0 0 0.0 1.0 0 0 0.0 0.131 0.915 0.269 0.868
## 2 Acinos arvensis 0.0 0 0.0 0.0 2 4 0.0 0.040 0.475 0.000 0.722
## 3 Arrhenatherum elatius 0.5 0 0.5 0.0 0 3 0.0 0.849 0.313 0.603 0.384
## 4 Bromus erectus 0.5 18 86.0 61.0 58 65 2.0 0.039 0.757 0.297 0.540
## 5 Bromus sterilis 0.5 4 0.0 0.0 0 0 0.0 0.385 0.317 0.495 0.391
## 6 Bupleurum baldense** 0.0 0 0.5 1.0 2 2 0.0 0.394 0.535 0.109 0.463
# 去掉NA值
grazed_data <- na.omit(grazed_data)
ungrazed_data <- na.omit(ungrazed_data)
# 提取群落数据
com1 <- grazed_data[, c("G1", "G2", "G3", "G4", "G5", "G6", "G7", "G8")]
rownames(com1) <- grazed_data$Species
com1 <- t(com1)
com1
com2 <- ungrazed_data[, c("N1", "N2", "N3", "N4", "N5", "N6", "N7")]
rownames(com2) <- ungrazed_data$Species
com2 <- t(com2)
com2
# 提取性状数据
traits1 <- grazed_data[, c("SLA", "LDMC", "N", "C")]
rownames(traits1) <- grazed_data$Species
traits1
traits2 <- ungrazed_data[, c("SLA", "LDMC", "N", "C")]
rownames(traits2) <- ungrazed_data$Species
traits2
数据准备好后,就可以开始计算功能多样性的各个成分了。
根据这个流程,我封装了一个函数来完成功能多样性三个组分的计算:
FD_DRQ <- function(traits, com) {
# 线性缩放性状数据到[0,1]范围
traits_scaled <- apply(traits, 2, function(x) (x - min(x)) / (max(x) - min(x)))
# 计算物种间的功能欧几里得距离
dist_func <- dist(traits_scaled, method = "euclidean")
# 将距离除以最大值进行缩放
dist_func_scaled <- dist_func / max(dist_func)
# 使用adiv包计算Simpson优势度(D)、功能冗余(R)和Rao's Q
S <- speciesdiv(com, "GiniSimpson")
colnames(S) <- "S"
Q <- QE(com, dist_func_scaled, "QE")
colnames(Q) <- "Q"
R <- S - Q
colnames(R) <- "R"
D <- 1 - S
colnames(D) <- "D"
# 创建DRQ数据框
DRQ <- data.frame(D = D, R = R, Q = Q)
return(DRQ)
}
FD_DRQ(traits1, com1)
## D R Q
## G1 0.1862207 0.4914946 0.3222847
## G2 0.1305590 0.5057338 0.3637071
## G3 0.2122165 0.3986428 0.3891407
## G4 0.1564776 0.4990360 0.3444864
## G5 0.1167779 0.5095429 0.3736792
## G6 0.1355194 0.4800773 0.3844033
## G7 0.1079387 0.4404172 0.4516440
## G8 0.1598319 0.5786248 0.2615433
FD_DRQ(traits2, com2)
## D R Q
## N1 0.5548090 0.2752250 0.1699660
## N2 0.2117788 0.5008637 0.2873574
## N3 0.2738727 0.4316556 0.2944718
## N4 0.3571282 0.4149361 0.2279357
## N5 0.2606493 0.4696835 0.2696672
## N6 0.2490568 0.5032315 0.2477117
## N7 0.5371157 0.2976231 0.1652613
DRQ <- FD_DRQ(traits1, com1)
ggtern(data = DRQ, aes(x = D, y = R, z = Q)) +
geom_point(shape=21,size=2,fill="red") +
theme_custom() +
labs(x = "D", y = "R", z = "Q")
# 合并两个数据集
data1 <- FD_DRQ(traits1, com1)
data1$group <- "Grazed"
data2 <- FD_DRQ(traits2, com2)
data2$group <- "Ungrazed"
data <- rbind(data1, data2)
data
# 创建三元图
ggtern(data = data, aes(x = D, y = R, z = Q, fill = group, shape = group)) +
geom_point(size = 2) +
theme_custom() +
labs(x = "D", y = "R", z = "Q") +
scale_fill_manual(values = c("Grazed" = "red", "Ungrazed" = "blue")) +
scale_shape_manual(values = c("Grazed" = 21, "Ungrazed" = 22)) +
theme(legend.background = element_blank(),
legend.key = element_blank())
参考来源
Ricotta, C., Podani, J., Schmera, D., Bacaro, G., Maccherini, S., & Pavoine, S. (2023). The ternary diagram of functional diversity. Methods in Ecology and Evolution, 14, 1168–1174. https://doi.org/10.1111/2041-210X.14100 Ricotta, C., Podani, J., Schmera, D., Bacaro, G., Maccherini, S., & Pavoine, S. (2023). Data from: The ternary diagram of functional diversity. Dryad Digital Repository. https://doi.org/10.5061/dryad.7pvmcvdzc