如何手动创建树状图(或“ hclust”)对象? (在R中) [英] How do I manually create a dendrogram (or "hclust") object ? (in R)

查看:184
本文介绍了如何手动创建树状图(或“ hclust”)对象? (在R中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我给了我一个树状图作为图像。由于它不是很大,因此我可以手工将其构造为R对象。

I have a dendrogram given to me as images. Since it is not very large, I can construct it "by hand" into an R object.

所以我的问题是如何手动创建树状图(或 hclust )对象,当我所有的都是树状图图像时?

So my question is how do I manually create a dendrogram (or "hclust") object when all I have is the dendrogram image?

我看到有一个名为 as.dendrogram的函数,但是我找不到一个示例有关如何使用它的信息。

I see that there is a function called "as.dendrogram" But I wasn't able to find an example on how to use it.

(ps:这篇帖子是我在

(p.s: This post is following my question from here)

非常感谢,
Tal

Many thanks, Tal

推荐答案

我认为您最好创建一个 hclust 对象,并且然后使用 as.dendrogram 将其转换为树状图,然后尝试直接创建树状图。查看?hclust 帮助页面,以了解 hclust 对象的元素的含义。

I think you are better of creating an hclust object, and then converting it to a dendrogram using as.dendrogram, then trying to create a dendrogram directly. Look at the ?hclust help page to see the meaning of the elements of an hclust object.

这里是一个简单的示例,其中有四个叶子A,B,C和D,先组合AB,再组合CD,最后组合AB-CD:

Here is a simple example with four leaves A, B, C, and D, combining first A-B, then C-D, and finally AB-CD:

a <- list()  # initialize empty object
# define merging pattern: 
#    negative numbers are leaves, 
#    positive are merged clusters (defined by row number in $merge)
a$merge <- matrix(c(-1, -2,
                    -3, -4,
                     1,  2), nc=2, byrow=TRUE ) 
a$height <- c(1, 1.5, 3)    # define merge heights
a$order <- 1:4              # order of leaves(trivial if hand-entered)
a$labels <- LETTERS[1:4]    # labels of leaves
class(a) <- "hclust"        # make it an hclust object
plot(a)                     # look at the result   

#convert to a dendrogram object if needed
ad <- as.dendrogram(a)

这篇关于如何手动创建树状图(或“ hclust”)对象? (在R中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆