3

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

Dave2e
  • 22,192
  • 18
  • 42
  • 50
C. Denney
  • 577
  • 4
  • 16
  • @Dave2e I have already used the cutree function to cut to the clusters I want, but as far as I can tell, there is no way to plot to where I cut it to. – C. Denney Aug 02 '17 at 23:48

1 Answers1

5

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.

Dave2e
  • 22,192
  • 18
  • 42
  • 50
  • Thanks, this has gotten me most of the way there, now I just have to figure out why my branch labels are misaligned! -edit- Figured it out, I needed the "center" parameter, per the dendrogram page. Thanks. – C. Denney Aug 03 '17 at 16:44
  • Thanks for this great answer! I am curious whether the groups correspond to what you'd receive from the `cutree()` function? – Kryštof Chytrý May 04 '23 at 10:52
  • 1
    @KryštofChytrý, no it seems the group numbers are assigned randomly between `cut` & `cutree` – Dave2e May 04 '23 at 22:18