C. Denney
C. Denney

Reputation: 627

Plotting hclust only to the cut clusters, not every leaf

I have an hclust tree with nearly 2000 samples. I have cut it to an appropriate number of clusters and would like to plot the dendrogram but ending at the height that I cut the clusters rather than all the way to every individual leaf. Every plotting guide is about coloring all the leaves by cluster or drawing a box, but nothing seems to just leave the leaves below the cut line out completely.

My full dendrogram looks like the following:

Full Dendrogram

I would like to plot it as if it stops where I've drawn the abline here (for example):

enter image description here

Upvotes: 4

Views: 1730

Answers (1)

Dave2e
Dave2e

Reputation: 24139

This should get you started. I suggest reading the help page for "dendrogram"

Here is the example from the help page:

hc <- hclust(dist(USArrests))
dend1 <- as.dendrogram(hc)
plot(dend1)
dend2 <- cut(dend1, h = 100)
plot(dend2$upper)
plot(dend2$upper, nodePar = list(pch = c(1,7), col = 2:1))

By performing the cut on the dendrogram object (not the hclust object) you can then plot the upper part of the dendrogram. It will take a some work to replace the branch1, 2, 3, and 4 labels depending on your analysis.

Good luck.

Upvotes: 6

Related Questions