首页 > 解决方案 > 如何重新排序 heatmap.2 中的列

问题描述

我正在尝试重新排序 heatmap.2 中的列顺序。

使用下面的代码,我获得了以下热图。

# load package
library(Heatplus)
library(gplots)

# create a matrix
m1 <- matrix(data = runif(600, 1, 1000),
             nrow = 100,
             ncol = 6)

# name the columns of the matrix
colnames(m1) <- paste0(rep(c("HIGH", "MEDIUM", "LOW"), each = 2))

# create color palette
my.colors <- colorpanel (64, low = "blue", mid = "white", high = "red")

# create heat map
heatmap.2(m1,
          scale ="row",
          distfun = function(x) dist(x,method = 'euclidean'), 
          hclustfun = hclust.ward, # agglomeration method
          Colv = T,
          trace="none",
          col = my.colors, # my color palette
          main = "how to switch the columns",
          srtCol = 45)# to change angle of the label)

需要对列重新排序的热图

我想对列重新排序(即只是“交换”列)并让具有相同处理的列彼此相邻。当然,这仅在列重新排序尊重图顶部树状图的层次结构时。

在提供的图中,这意味着将最左侧的“HIGH”列移动到最右侧,紧挨着另一个“HIGH”样本。

我知道可以翻转分支的功能“reorder.dendrogram”(来自这篇文章:R - heatmap.2: reorder rows and columns),但无法使其正常工作。

我认为这个问题是我无法访问(或找到)绘制上部树状图的对象。

非常感谢!瓦莱里安

标签: rheatmapbioconductordendrogram

解决方案


推荐阅读