我正在对 x 和 y 是空间坐标的大型空间数据集进行聚类分析。我正在使用 hclust 和 dynamicTreeCut,然后为了表示我使用 ggplot 显示散点图。
但我无法正确可视化集群,因为我只能在行或列中显示剪切。
这是我想要的玩具样本,但是对于我的数据,集群只能在水平方向工作(所以我认为它应该只对 y 进行集群或可视化)。
# x and y are coordinates of points in a map
x <- sample(1:1000, 80)
y <- sample(1:1000, 80)
df <- data.frame(x,y)
hc <- hclust(dist(df, "euclidean"),"complete");
maxCoreScatter <- 0.81
minGap <- (1 - maxCoreScatter) * 3/4
groups <- cutreeDynamic(hc, minClusterSize=1, method="hybrid", distM=as.matrix(dist(df)), deepSplit=4, maxCoreScatter=maxCoreScatter, minGap=minGap)
df$group <- groups
p <- ggplot(df, aes(x,y,colour=factor(groups))) + geom_point() + theme(aspect.ratio = 1)
p