如何在Pheatmap中翻转分层聚类节点

问题描述

我有以下代码:

pheatmap::pheatmap(mtcars,clustering_method = "ward.D2")

哪个会生成如下图?

enter image description here

我想做的就是做到这些:

  1. mpgqsec节点移到wt之后。
  2. disphp节点移到最左侧。

这是有效的做法吗?如果可以,我该如何实现?

更新

以下是Marco Marco的建议,并附有以下内容: tweek。我想出了完成此工作的这段代码:

phtmap <- pheatmap::pheatmap(mtcars)
col_dend <- phtmap[[2]]
col_dend <- dendextend::rotate(col_dend,order = c("hp","disp","vs","am","cyl","drat","gear","carb","wt","mpg","qsec") )
pheatmap(mtcars,cluster_cols=as.hclust(col_dend))

解决方法

也许这就是您想要的。

library(pheatmap)
library(seriation)
library(dendextend)

phtmap <- pheatmap(mtcars)
col_dend <- phtmap[[2]]
col_dend <- rotate(col_dend,order = rev(names(mtcars)[get_order(col_dend)]))

# The pheatmap with the same clustering of heatmaply
pheatmap(mtcars,cluster_cols=as.hclust(col_dend))

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...