如何在层次聚类后提取从gplots创建的热图中提取的矩阵?

时间:2016-02-25 19:51:22

标签: r heatmap gplots

我正在制作热图,但我无法在变量中分配结果以在绘图前检查结果。 Rstudio自动绘制它。我想按照热图的顺序获取rownames列表。我不确定这是否可行。我正在使用此代码:

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 ] )

2 个答案:

答案 0 :(得分: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

如果您浏览列表元素,您将会看到与树形图和热图关联的所有其他值。

答案 1 :(得分:0)

对于其他人来说,有一种更完整的描述方式来捕获由gplots创建的热图的矩阵表示:

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