[BioC] heatmap.2() get matrix after hierarchical clustering

Thomas Girke thomas.girke at ucr.edu
Tue Oct 16 17:42:10 CEST 2012


Try:

## Some input sample matrix 
y <- matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""), paste("t", 1:5, sep="")))

## Run heatmap.2 on this matrix
library(gplots)
test <- heatmap.2(y)
y[rev(test$rowInd), test$colInd]

Now try to understand why y[rev(test$rowInd), test$colInd] does the
trick of returning the row names/labels in the proper order, which is
just some basic R syntax of accessing a list-like object and then
using an index for sorting.

Another way of doing this is to separate the clustering with hclust from the 
heatmap plotting, where you want to learn how to access the hclust object as 
you need. 

For instance:

## Row clustering (adjust here distance/linkage methods to what you need!)
hr <- hclust(as.dist(1-cor(t(y), method="pearson")), method="complete")

## Column clustering (adjust here distance/linkage methods to what you need!)
hc <- hclust(as.dist(1-cor(y, method="spearman")), method="complete")

## Plot heatmap
heatmap.2(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc), scale="row", density.info="none", trace="none")

## Return matrix with row/column sorting as in heatmap
y[rev(hr$labels[hr$order]), hc$labels[hc$order]]


Thomas

On Tue, Oct 16, 2012 at 02:32:35PM +0000, Guest [guest] wrote:
> 
> Hi,
> 
> Is there an easy way to obtain the matrix after the heatmap.2() function performs clustering. I'm plotting a matrix of fold change values with 359 genes. The names of the genes are not visible on the heatmap since there are so many. I want to view this matrix after the clustering is performed since the order of the genes from the input matrix is rearranged.
> 
> Any input will be appreciated.
> 
> Thanks!
> 
>  -- output of sessionInfo(): 
> 
> N/A
> 
> --
> Sent via the guest posting facility at bioconductor.org.
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list