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:

1
2
3
4
5
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.

comments powered by Disqus
CC-BY-NC 4.0
Built with Hugo Theme Stack