r - 如何重新排序 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),但无法使其正常工作。
我认为这个问题是我无法访问(或找到)绘制上部树状图的对象。
非常感谢!瓦莱里安
解决方案
推荐阅读
- python - 获取下拉数据并更新Django中的数据
- android - 应用程序在移动到下一个活动时崩溃
- git - GitAttribute 强制手动合并特定文件
- javascript - 附加新选项时选择选项消失
- c - 我可以将 char* 数组而不是几个参数传递给函数吗?
- javascript - 如何停止对“dragover”事件的口吃
- algorithm - 在合并排序中的上一次递归期间,有什么方法可以将返回值用作同一函数的参数
- javascript - 用 js 附加回显元素
- java - 我的 JavaFX 项目在 EventHandler 处停止运行代码
- python - 在 numpy 中保持维度的数组的索引列表