【问题标题】:Clustering- Plotting largest n clusters聚类 - 绘制最大的 n 个聚类
【发布时间】:2016-11-23 00:04:46
【问题描述】:

我正在使用 HOPACH 聚类 - 有没有办法只可视化最大的 n 个聚类(例如,只绘制 3 个最大的聚类)?当前代码可视化所有集群。

library(cluster)
library(hopach) 

distance =distancematrix(DNA[1:30],"cosangle")
hobpach.DNA =hopach(DNA[1:30],dmat=distance)

labels = c(hobpach.DNA$clustering$labels) 

table(labels, DNA$class)

#Plots all clusters

clusplot(DNA[1:30], hobpach.DNA$clustering$labels, main='Cluster Vis',
     color=TRUE, shade=TRUE,
     labels=2, lines=0)

【问题讨论】:

    标签: r cluster-analysis


    【解决方案1】:

    clusplot 中没有类似的内容。但是您可以轻松找出哪些集群最大,然后只将它们提供给clusplot 函数。

    # find the indicees of the largest clusters
    biggest_indicees <- labels %in% names(sort(table(labels), decreasing = TRUE)[1:3])
    
    # plot three largest clusters
    clusplot(df[biggest_indicees, ], labels[biggest_indicees], main = 'Cluster Vis',
             color = TRUE, shade = TRUE, labels = 2, lines = 0)
    

    【讨论】:

    • 我有一个小问题... df[biggest_indicees, ] 中的错误:'closure' 类型的对象不是子集
    • 您是否定义了上面代码中提到的标签?你有labels = c(hobpach.DNA$clustering$labels)
    • 是的,完全正确-我已经在网上搜索过这个问题,但没有运气。
    • 尝试只打印标签,看看是否符合您的预期。
    • 我相信这是我想要的。 'str(labels) num [1:846] 32000 22000 10000 22000 31100 ...'
    猜你喜欢
    • 2020-02-04
    • 1970-01-01
    • 2020-08-28
    • 2019-09-26
    • 2019-10-01
    • 2022-06-14
    • 2014-12-06
    • 1970-01-01
    • 2012-07-19
    相关资源
    最近更新 更多