I am trying to extract the colors used in the clustering of circlize_dendrogram
. Here is a sample codes:
library(magrittr)
library(dendextend)
cols <- c("#009000", "#FF033E", "#CB410B", "#3B444B", "#007FFF")
dend <- iris[1:40,-5] %>% dist %>% hclust %>% as.dendrogram
dend <- color_branches(dend, k = 5, col = cols)
dend %<>% set("labels_col", value = cols, k= 5)
dend %<>% set("labels_cex", .8)
dend %<>% set("branches_lwd", 2)
circlize_dendrogram(dend)
So that the tabulated clusters are extracted using cutree(dend, k = 5)
. Is there a way to extract the colors of the clusters in the dendrogram based on the cols
given? I need it for inserting a legend in the plot using the grid
package.
Example, Legend: Cluster 1 - #009000
; Cluster 2 - #FF033E
; Cluster 3 - #CB410B
; Cluster 4 - #3B444B
; Cluster 5 - #007FFF
. The problem with the circlize_dendrogram
is the ordering of the colors used for cluster is different.
Although I can do this manually, it would be efficient if I can do it automatically. And that's possible if I can extract the colors of the clusters.