I am manually cutting a dendrogram created from hclust
in R using identify.hclust
.
The default return of the function is the IDs of observations in each group.
I need this information, but I also need to know the height of this group. Is there any way of doing it? Thanks alot!
Reproducible data:
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
As example, I cut the dendrogram at the following heights by using identify
and want to get the height of the merge for the branch:
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")
I suspect you could get your answer from the two functions
heights_per_k.dendrogram
andget_branches_heights
from the R package dendextend.Here is a small example:
For example:
Does this give you the tools for getting your answer?