library(pheatmap)
library(heatmaply)
library(seriation)
library(dendextend)
# A dataset
x <- scale(mtcars)
# Interactive heatmap
p <- heatmaply(x)
print(p)
# The dendrogram for rows
dst <- dist(x)
hc_row <- hclust(dst)
row_dend <- as.dendrogram(hc_row)
row_dend <- seriate_dendrogram(row_dend, dst, method="OLO")
# The dendrogram for columns
dst <- dist(t(x))
hc_row <- hclust(dst)
col_dend <- as.dendrogram(hc_row)
col_dend <- seriate_dendrogram(col_dend, dst, method="OLO")
col_dend <- rotate(col_dend, order = rev(labels(dst)[get_order(as.hclust(col_dend))]))
# The pheatmap with the same clustering of heatmaply
pheatmap(x, cluster_rows=as.hclust(row_dend), cluster_cols=as.hclust(col_dend))
的输出heatmaply
和输出pheatmap