How to plot dendrograms with large datasets?

♀尐吖头ヾ 提交于 2019-12-02 15:52:24

The cut function described in the other answer is a very good solution; if you would like to maintain the whole tree on one page for some interactive investigation you could also plot to a large page on a PDF.

The resulting PDF is vectorized so you can zoom in closely with your favourite PDF viewer without loss of resolution.

Here's an example of how to direct plot output to PDF:

# Open a PDF for plotting; units are inches by default
pdf("/path/to/a/pdf/file.pdf", width=40, height=15)

# Do some plotting
plot(gcPhylo)

# Close the PDF file's associated graphics device (necessary to finalize the output)
dev.off()

It is possible to cut a dendrogram at a specified height and plot the elements:

First create a clustering using the built-in dataset USArrests. Then convert to a dendrogram:

hc <- hclust(dist(USArrests))
hcd <- as.dendrogram(hc)

Next, use cut.dendrogram to cut at a specified height, in this case h=75. This produces a list of a dendrogram for the upper bit of the cut, and a list of dendograms, one for each branch below the cut:

par(mfrow=c(3,1))

plot(hcd, main="Main")
plot(cut(hcd, h=75)$upper, 
     main="Upper tree of cut at h=75")
plot(cut(hcd, h=75)$lower[[2]], 
     main="Second branch of lower tree with cut at h=75")

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