[BioC] Heatmap - color key & modifying text

Benilton Carvalho bcarvalh at jhsph.edu
Thu Sep 15 23:02:04 CEST 2005


this is what i usually do...

you might want to change the function, since it assumes a square matrix.

don't forget to load "fields" before.
b.

> 1) add a key that shows the heatmap color scheme order, say from low  to high

## this function assumes a square matrix
## small changes if this is not your case
##   but this is what i need for now :)
##
## Call:
##      myheatmap(mymatrix,
##                order=the.order.you.want.the.matrix.to.be.plotted,
##                col=the.colors,
##                zr=range.is.vec.2.elements,
##                names=vec.with.names.of.columns.rows,
##                ...)  #whatever you want to send to image()
##
##
##  Try:  myheatmap(matrix(rnorm(100),ncol=10))
##
##   given my configuration, you'll probably need
##      to maximize your window

library(fields)
myheatmap <- function (mymatrix, order = 1:ncol(mymatrix),
                        col = heat.colors(1024)[1024:1],
                        zr = range(mymatrix),
                        names = NULL, ...){
   par(plt = c(0.25, 0.9, 0.1, 0.9))
   ncols <- ncol(mymatrix)
   image(t(mymatrix[order, order])[, ncols:1], col = col,
         axes = FALSE, zlim = zr, ...)
   sn <- paste(names(mymatrix),1:ncols)[order]
   if (!is.null(names))
     sn <- paste(sn,names[order])
   axis(2, at = (0:(ncols - 1))/(ncols - 1), labels = sn[ncols:1],
        las = 1)
   image.plot(t(mymatrix[order, order])[, ncols:1],
              horizontal = TRUE, legend.only = TRUE, zlim = zr, col = col,
              smallplot = c(0.25, 0.9, 0.05, 0.095))
}



More information about the Bioconductor mailing list