heatmap.2指定行顺序还是防止重新排序? [英] heatmap.2 specify row order OR prevent reorder?

查看:562
本文介绍了heatmap.2指定行顺序还是防止重新排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用heatmap.2(下面的代码)生成一些经对数转换的倍数变化数据的图.

I'm trying to generate some plots of log-transformed fold-change data using heatmap.2 (code below).

我想按最后一列(最大到最小)中的值对热图中的行进行排序.这些行是自动排序的(我不确定在幕后"使用的精确计算),如图中所示,正在执行一些聚类.

I'd like to order the rows in the heatmap by the values in the last column (largest to smallest). The rows are being ordered automatically (I'm unsure the precise calculation used 'under the hood') and as shown in the image, there is some clustering being performed.

sample_data

gid     2hrs    4hrs    6hrs    8hrs
1234    0.5     0.75    0.9     2
2234    0       0       1.5     2
3234    -0.5    0.1     1       3
4234    -0.2    -0.2    0.4     2
5234    -0.5    1.2     1      -0.5
6234    -0.5    1.3     2      -0.3
7234    1       1.2    0.5      2
8234    -1.3    -0.2    2       1.2
9234    0.2     0.2     0.2     1
0123    0.2     0.2     3       0.5

代码

data <- read.csv(infile, sep='\t',comment.char="#")
rnames <- data[,1]                 # assign labels in column 1 to "rnames"
mat_data <- data.matrix(data[,2:ncol(data)])  # transform columns into a matrix
rownames(mat_data) <- rnames                  # assign row names

# custom palette
my_palette <- colorRampPalette(c("turquoise", "yellow", "red"))(n = 299)
# (optional) defines the color breaks manually for a "skewed" color transition
col_breaks = c(seq(-4,-1,length=100),  # for red
seq(-1,1,length=100),              # for yellow
seq(1,4,length=100))              # for green

# plot data
heatmap.2(mat_data,
density.info="none",  # turns off density plot inside color legend
trace="none",         # turns off trace lines inside the heat map
margins =c(12,9),     # widens margins around plot
col=my_palette,       # use on color palette defined earlier
breaks=col_breaks,    # enable color transition at specified limits
dendrogram='none',     # only draw a row dendrogram
Colv=FALSE)            # turn off column clustering

情节

我想知道是否有人可以建议如何关闭重新排序,以便我可以在最后一列之前对矩阵进行重新排序并强制使用此顺序,或者可以通过选择heatmap.2函数来做到这一点.

I'm wondering if anyone can suggest either how to turn off reordering so I can reorder my matrix by the last column and force this order to be used, or alternatively hack the heatmap.2 function to do this.

推荐答案

您未指定Rowv=FALSE,并且默认情况下对行进行了重新排序(在heatmap.2帮助中,对于参数Rowv:

You are not specifying Rowv=FALSE and by default the rows are reordered (in heatmap.2 help, for parameter Rowv :

确定是否以及如何对行树状图进行重新排序.经过 默认情况下,它为TRUE,这意味着将计算树状图并 根据行均值重新排序.如果为NULL或FALSE,则没有树状图 计算且不进行重新排序.

determines if and how the row dendrogram should be reordered. By default, it is TRUE, which implies dendrogram is computed and reordered based on row means. If NULL or FALSE, then no dendrogram is computed and no reordering is done.

因此,如果您希望根据最后一列对行进行排序,则可以执行以下操作:

So if you want to have the rows ordered according to the last columns, you can do :

mat_data<-mat_data[order(mat_data[,ncol(mat_data)],decreasing=T),]

然后

heatmap.2(mat_data,
density.info="none",  
trace="none",         
margins =c(12,9),    
col=my_palette,       
breaks=col_breaks,   
dendrogram='none',     
Rowv=FALSE,
Colv=FALSE)     

您将获得以下图像:

You will get the following image :

这篇关于heatmap.2指定行顺序还是防止重新排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆