如何标记切割树状图的终端节点?
我使用以下代码在特定高度切割树状图。我遇到的问题是,当我切割树状图时,我不知道如何向节点添加标签。如何切割带有标签的树状图使用R程序?
library(Heatplus)
cc=as.dendrogram(hclust(as.dist(mat),method="single"))
cutplot.dendrogram(cc,h=20)
I used the following code to cut the dendrogram at a particular height.The problem I'm having is that when I cut a dendrogram, I can't figure out how to add labels to the nodes.How can I cut a dendrogram with labels using R program?
library(Heatplus)
cc=as.dendrogram(hclust(as.dist(mat),method="single"))
cutplot.dendrogram(cc,h=20)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在深入研究了
?dendrogram
的帮助文档后,我偶然发现了dendrapply
函数,其中包含一个执行非常类似操作的示例。这是基于?dendrapply
中示例的修改的解决方案:创建树状图并在高度处切割
h=20
:使用 newLabels 和函数定义一个向量
newLab
修改单个节点标签。然后将其传递给dendrapply
:After a fair amount of digging into the help documentation for
?dendrogram
, I stumbled on thedendrapply
function that contains an example to do something very similar. Here is your solution, based on a modification of the example in?dendrapply
:Create dendrogram and cut at height
h=20
:Define a vector with the newLabels, and a function
newLab
that modifies an individual node label. Then pass this todendrapply
:这是 Andrie 编写的修改后的解决方案,但使用了一个名为“dendextend”的新包,专门为这种事。
您可以在包的演示文稿和插图中看到许多示例,位于以下 URL 的“用法”部分:https: //github.com/talgalili/dendextend
这是这个问题的解决方案:
要安装包(因为我还没有将其上传到 CRAN),请使用:
Best,
塔尔
Here is a modified solution for what Andrie wrote, but using a new package called "dendextend", built exactly for this sort of thing.
You can see many examples in the presentations and vignettes of the package, in the "usage" section in the following URL: https://github.com/talgalili/dendextend
Here is the solution for this question:
For installing the package (since I have yet to upload it to CRAN), use:
Best,
Tal
这是树状图中所有元素的向量。
您可以添加自己的矢量来更改标签
This is a vector of all the elements in the dendogram.
You can add in your own vector to change the labels