library(ComplexHeatmap)
library(circlize)
library(dendextend)
library(RColorBrewer)
df<-scale(mtcars)
row_dend = hclust(dist(df))
col_dend = hclust(dist(t(df)))
mycol <-rev(brewer.pal(n = 7, name = "RdYlBu"))
Heatmap(df, col = mycol,name = "mtcars",rect_gp = gpar(col = "black"),
column_dend_height = unit(4, "cm"),
row_dend_width = unit(4, "cm"),
cluster_rows = color_branches(row_dend, k = 4),
cluster_columns = color_branches(col_dend, k = 2))

library(gplots)
colormap <- colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100)
Rowv <- mtcars %>% scale %>% dist %>% hclust %>% as.dendrogram %>%
set("branches_k_color", k = 4) %>% set("branches_lwd", 1.2) %>%
ladderize
Colv <- mtcars %>% scale %>% t %>% dist %>% hclust %>% as.dendrogram %>%
set("branches_k_color", k = 2, value = c("orange", "blue")) %>%
set("branches_lwd", 1.2) %>%
ladderize
heatmap.2(scale(mtcars), scale = "none", col = colormap,
Rowv = Rowv, Colv = Colv,
trace = "none", density.info = "none")

library(RColorBrewer)
library(pheatmap)
colormap <- colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100)
breaks = seq(min(unlist(c(df))), max(unlist(c(df))), length.out=100)
pheatmap(df, color=colormap, breaks=breaks,border_color="black",
cutree_col = 2,cutree_row = 4)
