Plotting hclust only to the cut clusters, not every leaf

守給你的承諾、 提交于 2021-01-28 00:08:00

问题


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:

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


回答1:


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.



来源:https://stackoverflow.com/questions/45472549/plotting-hclust-only-to-the-cut-clusters-not-every-leaf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!