簡體   English   中英

heatmap.2指定行順序還是防止重新排序?

[英]heatmap.2 specify row order OR prevent reorder?

我正在嘗試使用heatmap.2生成一些對數轉換的折疊變化數據圖(下面的代碼)。

我想按照最后一列中的值(從大到小)對熱圖中的行進行排序。 這些行是自動排序的(我不確定在引擎蓋下使用的精確計算)並且如圖所示,正在執行一些聚類。

樣本數據

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函數來執行此操作。

您沒有指定Rowv=FALSE ,默認情況下會重新排序行(在heatmap.2幫助中,對於參數Rowv

確定是否以及如何重新排序行樹形圖。 默認情況下,它為TRUE,這意味着樹形圖是基於行平均值計算和重新排序的。 如果為NULL或FALSE,則不計算樹形圖並且不進行重新排序。

因此,如果您希望根據最后一列排序行,您可以執行以下操作:

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)     

您將看到以下圖像: 在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM