Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

cluster analysis - How do I manually create a dendrogram (or "hclust") object ? (in 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.

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

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

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

Many thanks, Tal

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...