Color dendrogram branches based on external labels uptowards the root until the label matches
问题 From question Color branches of dendrogram using an existing column, I can color the branches near the leaf of the dendrogram. The code: x<-1:100 dim(x)<-c(10,10) set.seed(1) groups<-c("red","red", "red", "red", "blue", "blue", "blue","blue", "red", "blue") x.clust<-as.dendrogram(hclust(dist(x))) x.clust.dend <- x.clust labels_colors(x.clust.dend) <- groups x.clust.dend <- assign_values_to_leaves_edgePar(x.clust.dend, value = groups, edgePar = "col") # add the colors. x.clust.dend <- assign