I'm wondering what's the way in which for a given depth cutoff in dendrogram
I can get for each branch below that depth cutoff a list of the names of all the leaves which are its descendants.
For example I create this dendrogram
:
set.seed(1)
mat <- matrix(rnorm(100*10),nrow=100,ncol=10)
dend <- as.dendrogram(hclust(dist(t(mat))))
Plotting it using dendextend
:
require(dendextend)
dend %>% plot
And defining the depth cutoff as 14.5:
abline(h=14.5,col="red")
my list should be:
list(c(5),c(7),c(8),c(10,4,9),c(3,6,1,2))
Not entirely sure if this is the answer you are after, but can you just access them like this?
Presumably you want to do this automatically so then it would be something like
There is probably a more elegant way to do this I think, but this doesn't look like a terrible way to do it.
EDIT
Since the user completely changed the question here is a new answer here:
You just need to access the height of each terminal node in the dendrogram and determine if it is above or below the height you want it to be. Unfortunately this won't group together the leaf nodes that come from the same parent - however, this shouldn't be too difficult to add on with a bit of tinkering. Hopefully this gets you on your way.