【问题标题】:Get the cut heights using identify.hclust()使用 identify.hclust() 获取切割高度
【发布时间】:2017-05-08 10:02:06
【问题描述】:

我正在使用 identify.hclust 在 R 中手动切割从 hclust 创建的树状图。 该函数的默认返回是每组中观察的 ID。 我需要这些信息,但我也需要知道这个组的高度。有什么办法吗?非常感谢!

可重现的数据:

set.seed(1)
dat = rnorm(100,0,1)
hca = hclust(dist(dat))
plot(hca, hang=-1, sub="", xlab="", labels=F)
heightsAndIDs = identify(hca) #Gives only IDs

例如,我使用identify 在以下高度切割树状图,并希望获得分支的合并高度:

segments(3,2,8, col="red")
segments(15,1,18, col="green")
segments(20,1,24,col="blue")
segments(38,1.5,45,col="purple")
segments(75, 1.5, 82,col="cyan")

【问题讨论】:

  • 除了identify()试试locator()
  • 谢谢,这肯定会帮助我。现在我需要将它与默认返回结合起来

标签: r dendrogram hclust


【解决方案1】:

我怀疑你可以从 R 包 dendextend 中的两个函数 heights_per_k.dendrogramget_branches_heights 中得到答案。

这是一个小例子:

set.seed(1)
dat = rnorm(100,0,1)
hca = hclust(dist(dat))

library(dendextend)

例如:

> sort(heights_per_k.dendrogram(dend))[1:7]
          100            99            98 
0.00002485728 0.00010400211 0.00020365009 
           97            96            95 
0.00118445439 0.00180321776 0.00215161572 
           94 
0.00230368982 
> sort(heights_per_k.dendrogram(dend), T)[1:7]
        1         2         3         4         5 
4.6163377 4.6162976 3.1585161 1.8779138 1.3384979 
        6         7 
1.1705453 0.9620798 

这是否为您提供了获得答案的工具?

【讨论】:

    猜你喜欢
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    相关资源
    最近更新 更多