r - 如何在 R 中使用聚类分析来识别仅给定存在-不存在数据的植被群落?
问题描述
我正在尝试使用基于样方的植被调查的结果来识别大片土地上离散的草本植物群落。然而,除了给定样方中物种的简单存在或不存在外,没有记录任何数据。在这种情况下,有什么方法可以使用 TRUE/FALSE 值来代替物种丰度或潜在相关环境变量的任何定量数据?我的目标是生成一个图形,将样方显示为点,并以图形方式识别具有相似植被组合的样方集群。
到目前为止,我可以编辑这篇文章以包含我的代码,但我选择暂时不包含它,因为我不知道我的整个方法是否存在缺陷。
数据当前存储为 .csv,其中列是物种,行是单个样方,单元格显示 TRUE(在样方中存在)或 FALSE(在样方中不存在)。
解决方案
我使用 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)
这有帮助吗?
推荐阅读
- corda - Corda 3.3 和 Open JDK
- ms-access - 丝带形式。图像对象。如何以编程方式设置表单元素“图片”中图片的路径?
- javascript - Kendo UI Grid excel 导出
- java - 在打印日志时使用方法名称作为记录器的参数是不好的做法吗?
- php - 如何获取数组列表中对象中的键和值
- objective-c - renderInContext:函数在 Mojave 10.14.4 中不起作用
- python-3.x - 多个摄像头馈送不适用于 PyQt5 线程:
- arm - 在 arm-cortex-m4 FREERTOS 中实现 SIP 协议
- python - 使用 Python 的 itertools 的二维表索引生成器
- c# - 如何在 DQN(深度 Q 网络)中分配状态?