I am using the heatmaply package to create heatmaps with dendrograms from the dendextend package. Is there a way to identify the cluster numbers on the dendrogram? This is an example heatmap for the mtcars dataset. I want cluster numbers on the dendrogram (or a legend) like the ones I manually put in red. This is the code for replication:
library(dendextend, datasets, heatmaply)
row_dend <- mtcars %>% dist %>% hclust %>% as.dendrogram %>%
set("branches_k_color", value = c(1:8), k = 8) %>%
set("branches_lwd", 1)
col_dend <- mtcars%>% t %>% dist %>% hclust %>% as.dendrogram %>%
set("branches_k_color", value = c(1:8), k = 8) %>%
set("branches_lwd", 1)
heatmaply_mtcars <-
heatmaply(mtcars, hclustfun = hclust, hclust_method = "ward.D2",
Rowv = row_dend,
Colv = col_dend,
xlab = "x axis",
ylab = "y axis",
showticklabels = c(TRUE, TRUE),
scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(high = "#025492"),
file = "inter_heatmap.html",
column_text_angle = 30,
colorbar_thickness = 50)