Nathan VanHoudnos Nathan VanHoudnos - 1 year ago 39
R Question

display a matrix, including the values, as a heatmap

What I'd like to do is take this matrix:

> partb
0.5 1.5 1a 1b -2 -3
A1FCLYRBAB430F 0.26 0.00 0.74 0.00 0.00 0.00
A1SO604B523Q68 0.67 0.33 0.00 0.00 0.00 0.00
A386SQL39RBV7G 0.00 0.33 0.33 0.33 0.00 0.00
A3GTXOXRSE74WD 0.41 0.00 0.08 0.03 0.05 0.44
A3OOD9IMOHPPFQ 0.00 0.00 0.33 0.00 0.33 0.33
A8AZ39QM2A9SO 0.13 0.54 0.18 0.13 0.00 0.03


And then make a heatmap that has each of the values in the now colored cells.

Making a heatmap is easy:

> heatmap( partb, Rowv=NA, Colv=NA, col = heat.colors(256), margins=c(5,10))


But for the life of me I can't figure out how to put the value in each of the cells.

What am I missing? Surely this is a common thing.

Answer Source

Try heatmap.2 from the gplots package. The cellnote and notecol parameters control the text placed in cells. You'll probably want dendrogram = "none" as well.