问题描述
我想创建一个数据框,其中包含我的行名,根据hclust
的顺序以及根据cutree
的组成员身份。我很难协调这些功能的输出。
d <- dist(USArrests)
hc <- hclust(d)
pheatmap::pheatmap(as.matrix(d)[hc$order,hc$order],cluster_cols = F,cluster_rows = F) # what I expect to see
data.frame(
state = hc$labels,hc = cutree(hc,h = 0),# hc doesn't match heat map
family = cutree(hc,k = 5) # family order doesn't agree with hc order
)
根据我对层次结构集群的理解,hc
和family
应该都处于同一顺序。例如:
hc = 1 2 3 4 5 6 # smallest to greatest
family = 1 1 2 2 2 3 # smallest to greatest
更新:
这为我提供了我想要的结果,我想看看是否有更简单的方法
data.frame(state = hc$labels[hc$order],row = 1:length(hc$labels),family = cutree(hc,k = 5)[hc$order]
)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)