用正确的组号标记R树状图分支 [英] Label R dendrogram branches with correct group number

查看:128
本文介绍了用正确的组号标记R树状图分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制树状图,以使分支上的标签与我的聚类分析中的组号匹配。当前,分支只是按照从左到右的顺序显示,而不是实际的组号。这是我当前的R代码和生成的树状图:

I am trying to draw a dendrogram so that the labels on the branches match the group number from my cluster analysis. Currently the branches are simply labelled from left to right in the order that they appear, not the actual group number. Here is my current R code and resulting dendrogram:

dst <- dist(Model_Results,method="binary") 
hca <- hclust(dst)
clust <- cutree(hca,k=40)
dend <-as.dendrogram(hca)
library(dendextend)
dend1 <- color_branches(dend, k = 40, groupLabels = TRUE)
plot(dend1)

如何更改标签以匹配我的实际组号?

How can I change the labels to match to my actual group number?

推荐答案

我想我终于设法弄清楚了...

I think I finally managed to figure it out...

dst <- dist(Model_Results,method="binary") 
hca <- hclust(dst)
clust <- cutree(hca,k=40)
dend <-as.dendrogram(hca)
library(dendextend)
clust.cutree <- dendextend:::cutree(dend, k=40, order_clusters_as_data = FALSE)
idx <- order(as.numeric(names(clust.cutree)))
clust.cutree <- clust.cutree[idx]
tbl <- table(clust, clust.cutree)
lbls <- apply(tbl,2,which.max)
dend1 <- color_branches(dend, k = 40, groupLabels = lbls)
plot(dend1)

这篇关于用正确的组号标记R树状图分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆