如何在层次聚类后提取从使用 gplots 创建的热图派生的矩阵?
How can I extract the matrix derived from a heatmap created with gplots after hierarchical clustering?
我正在制作热图,但无法将结果分配给变量以在绘图前检查结果。 Rstudio 会自动绘制它。我想按照热图的顺序获取行名列表。我不确定这是否可能。我正在使用此代码:
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 ] )
您可以将地块分配给对象。该图仍将绘制在图 window 中,但是,您还将获得一个列表,其中包含每个图元素的所有数据。然后您只需要从列表中提取所需的绘图元素。例如:
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
如果您探索列表元素,您将看到与树状图和热图关联的所有其他值。
对于那里的其他人,一种更完整的描述方法来捕获由 gplots 创建的热图的矩阵表示:
matrix_map <- p$carpet
matrix_map <- t(matrix_map)
我正在制作热图,但无法将结果分配给变量以在绘图前检查结果。 Rstudio 会自动绘制它。我想按照热图的顺序获取行名列表。我不确定这是否可能。我正在使用此代码:
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 ] )
您可以将地块分配给对象。该图仍将绘制在图 window 中,但是,您还将获得一个列表,其中包含每个图元素的所有数据。然后您只需要从列表中提取所需的绘图元素。例如:
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
如果您探索列表元素,您将看到与树状图和热图关联的所有其他值。
对于那里的其他人,一种更完整的描述方法来捕获由 gplots 创建的热图的矩阵表示:
matrix_map <- p$carpet
matrix_map <- t(matrix_map)