首页 > 解决方案 > 如何在 R 中使用聚类分析来识别仅给定存在-不存在数据的植被群落?

问题描述

我正在尝试使用基于样方的植被调查的结果来识别大片土地上离散的草本植物群落。然而,除了给定样方中物种的简单存在或不存在外,没有记录任何数据。在这种情况下,有什么方法可以使用 TRUE/FALSE 值来代替物种丰度或潜在相关环境变量的任何定量数据?我的目标是生成一个图形,将样方显示为点,并以图形方式识别具有相似植被组合的样方集群。

到目前为止,我可以编辑这篇文章以包含我的代码,但我选择暂时不包含它,因为我不知道我的整个方法是否存在缺陷。

数据当前存储为 .csv,其中列是物种,行是单个样方,单元格显示 TRUE(在样方中存在)或 FALSE(在样方中不存在)。

标签: rcluster-analysis

解决方案


我使用 stats::kmeans 开发了一个模拟示例

library(ggplot2)
set.seed(1235)

# Example TRUE/FALSE quadrat data:
quads = matrix(runif(400) > 0.7, nrow = 20)

# convert this to x, y data of TRUE quadrats:
xy = data.frame(which(quads, arr.ind = T))
names(xy) = c('X', 'Y')

# Number of clusters - to be determined by the data/model:
n_clusters = 5
km = kmeans(xy, n_clusters)
centers = data.frame(km$centers)

# add this to the quadrat data:
xy = cbind(xy, cluster=km$cluster)
 
# Plot
ggplot(data=xy) + 
  geom_point(aes(X,Y, col=as.factor(cluster)), size=2) + 
  geom_point(data=centers, aes(X, Y, col=as.factor(row.names(centers))),
             size = 5, shape=13, stroke=3)

使用 k-means 的示例聚类

这有帮助吗?


推荐阅读