2016-02-25 66 views
0

我正在製作熱圖,但在繪圖之前我無法將結果分配給變量以檢查結果。 Rstudio自動繪製它。我想按照熱圖的順序得到rownames的列表。我不確定這是否可能。使用此代碼我':如何在層次聚類後提取由gplots創建的熱圖所衍生的矩陣?

hm <- heatmap.2(assay(vsd)[ topVarGenes, ], scale="row", 
     trace="none", dendrogram="both", 
     col = colorRampPalette(rev(brewer.pal(9, "RdBu")))(255), 
     ColSideColors = c(Controle="gray", Col1.7G2="darkgreen", JG="blue", Mix="orange")[ 
      colData(vsd)$condition ]) 

回答

1

可以分配情節的對象。繪圖仍將繪製在繪圖窗口中,但是,您還將獲得每個繪圖元素的所有數據的列表。然後,您只需從列表中提取所需的圖元。例如:

library(gplots) 

p = heatmap.2(as.matrix(mtcars), dendrogram="both", scale="row") 

p是隨着劇情的所有元素的列表。

p # Outputs all the data in the list; lots of output to the console 

str(p) # Struture of p; also lots of output to the console 

names(p) # Names of all the list elements 

p$rowInd # Ordering of the data rows 

p$carpet # The heatmap values 

如果您瀏覽列表元素,您會看到與樹形圖和熱圖相關的所有其他值。

+0

非常感謝你。讓我問你一件事。我可以只繪製熱圖的前n行嗎? –

0

爲了別人在那裏,更全面的描述的方式來捕捉gplots產生的熱圖的矩陣表示:

matrix_map <- p$carpet 
matrix_map <- t(matrix_map)