如何使用大型数据集绘制树状图?

发布于 2024-12-04 06:25:06 字数 419 浏览 1 评论 0原文

我在 R 中使用 ape(系统发育和进化分析)包,它具有树状图绘制功能。我使用以下命令读取 Newick 格式的数据,并使用绘图函数绘制树状图:

library("ape")
gcPhylo <-read.tree(file = "gc.tree")
plot(gcPhylo, show.node.label = TRUE)

由于数据集非常大,因此不可能看到树的较低级别的任何细节。我只能看到黑色区域,但看不到细节。我只能从顶部看到几层,然后看不到细节。

我想知道绘图功能是否有缩放功能。我尝试使用 xLim 和 yLim 限制区域,但是,它们只是限制区域,并且不会缩放以使细节可见。缩放或在不缩放的情况下使细节可见将解决我的问题。

我也很高兴知道任何其他可以帮助我克服问题的包、函数或工具。

谢谢。

I am using ape (Analysis of Phylogenetics and Evolution) package in R that has dendrogram drawing functionality. I use following commands to read the data in Newick format, and draw a dendrogram using the plot function:

library("ape")
gcPhylo <-read.tree(file = "gc.tree")
plot(gcPhylo, show.node.label = TRUE)

As the data set is quite large, it is impossible to see any details in the lower levels of the tree. I can see just black areas but no details. I can only see few levels from the top, and then no detail.

I was wondering if there is any zoom capability of the plot function. I tried to limit the area using xLim and yLim, however, they just limit the area, and do not zoom to make the details visible. Either zooming, or making the details visible without zooming will solve my problem.

I am also appreciated to know any other package, function, or tool that will help me overcoming the problem.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半步萧音过轻尘 2024-12-11 06:25:06

可以在指定高度切割树状图并绘制元素:

首先使用内置数据集USArrests创建聚类。然后转换为 dendrogram

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

接下来,使用 cut.dendrogram 在指定高度处进行切割,在本例中为 h=75。这会生成一个树状图列表,用于切割的位,以及树状图列表,每个树状图对应于切割下方的每个分支

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")

在此处输入图像描述

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")

enter image description here

走走停停 2024-12-11 06:25:06

其他答案中描述的 cut 函数是一个非常好的解决方案;如果您想将整个树保留在一页上进行一些交互式调查,您也可以绘制到 PDF 上的大页面。

生成的 PDF 已矢量化,因此您可以使用您喜爱的 PDF 查看器进行近距离放大,而不会损失分辨率。

以下是如何将绘图输出直接导出为 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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文