1

Here is a hclust object named hc1a and I want to convert it to a dendrogram object and plot it.

# Create hc1a and plot
hc1a <- list()
hc1a$merge <- matrix(c(-8, -9,
                      -1, -2,
                      -5,  1,
                      -7,  2,
                      -3,  4,
                       3,  5,
                      -4,  6,
                      -6,  7), ncol = 2, byrow = T)
hc1a$height <- c(0.01333333, 0.02000000, 0.03833333, 0.05500000, 0.06888889, 0.10555556, 0.13285714, 0.19625000)
hc1a$order <- c(4, 3, 2, 1, 7, 5, 9, 8, 6)           
hc1a$labels <- c(4136, 4137, 4139, 4141, 4292, 4302, 4303, 4305, 4306)
class(hc1a) <- "hclust" 
plot(hc1a)

# Convert hc1a to a dendrogram object and plot    
dend <- as.dendrogram(hc1a)
plot(dend)

The order of nodes in the two plots differ. A further check of order and nodes:

> order.dendrogram(dend)
[1] 6 4 5 8 9 3 7 1 2
> labels(dend)
[1] 4302 4141 4292 4305 4306 4139 4303 4136 4137
> 
> hc1a$order
[1] 4 3 2 1 7 5 9 8 6
> hc1a$labels
[1] 4136 4137 4139 4141 4292 4302 4303 4305 4306

I want to know why both order and labels are changed? How to plot the dend so that it has the same structure as plot(hc1a), i.e., the same node order, label, and the same tree.

Patrick
  • 1,057
  • 9
  • 23

0 Answers0