[R] heatmap color specification

Xiaohui chenxh007 at gmail.com
Fri Feb 9 20:25:59 CET 2007


hi,

I have a positive integer matrix like:

test<-matrix(c(1,2,2,2,2,1,1,2,3),3)

and based on the distant function I made like this:

generateDistMat<-function (target)
{
    n <- nrow(target)
    rn <- rownames(target)
    distM <- matrix(NA, n, n)
    diag(distM) <- 0
    for (i in 1:(n - 1)) for (j in (i + 1):n) {
        distM[i, j] <- length(which(target[i, ] != target[j,
            ]))
        distM[j, i] <- distM[i, j]
    }
    colnames(distM) <- rownames(distM) <- rn
    distM
}

dist.fun <- function(M) return(as.dist(generateDistMat(M)))

Then, I did a heatmap for 'test' matrix. But for now, I want to specify 
each of the cell in the heatmap according to the values of the 
corresponding matrix elements of test.

Let's say: col<-c("red","yellow","green")

for test[1,1], the color on the map should be "red".

I have tried par('usr') and par('mar') with rect function. But this does 
not work because the rect shift from the original map. Could any one 
tell me how to fill the cells on the map with corresponding values? Or 
can we get the actual coordinates of the image excluding the dendregram. 
Any help would be appreciated. Thanks in advance!

Xiaohui



More information about the R-help mailing list