## 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
test <- heatmap.2(y)
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
heatmap plotting, where you want to learn how to access the hclust
## Row clustering (adjust here distance/linkage methods to what you
hr <- hclust(as.dist(1-cor(t(y), method="pearson")),
## Column clustering (adjust here distance/linkage methods to what you
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
On Tue, Oct 16, 2012 at 02:32:35PM +0000, Guest [guest] wrote:
> 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.
> -- output of sessionInfo():
> Sent via the guest posting facility at bioconductor.org.
> Bioconductor mailing list
> Bioconductor at r-project.org
> Search the archives: