R heatmap.2: get re-ordered matrix after hierarchical clustering

When you make a hierarchical clustering with the option Colv on, rows in the matrix will be re-ordered. Of course you can set the labRow on to show row labels, but they will be difficult to recognize if there are many rows. To get the re-ordered matrix, do the following:

library(gplots) # say you have a data matrix called ‘MATRIX’ h<-heatmap.2(MATRIX) matrix.new<-MATRIX[rev(h$rowInd), h$colInd] write.table(row.names(matrix.new), quote=F)

See explanation and inspiration here.

Z. Lu avatar
Z. Lu
Data mining, bioinformatics, parasites, retro, plain text.
comments powered by Disqus