【问题标题】:Using heatmaply dendrogram sorting in pheatmap在 pheatmap 中使用 heatmaply 树状图排序
【发布时间】:2020-07-15 13:27:07
【问题描述】:
有没有办法使用heatmaply 包中使用的树状图聚类方法并将其应用于pheatmap 包生成的热图?基本上与这里所问的相反:Clustering in pheatmap and heatmaply R packages
当我使用 heatmaply 而不是 pheatmap 时,我通常会看到更好的数据聚类。但是,我并不总是想使用交互式绘图。 heatmaply::ggheatmap 函数对我来说不能正常工作,因为我有 col_side_colors 并且注释妨碍了树状图。它只是看起来很乱。所以我改用pheatmap。
也许有人可以帮助解决我的问题。
谢谢!
【问题讨论】:
标签:
r
hierarchical-clustering
pheatmap
heatmaply
【解决方案1】:
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 的输出