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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…