[R] heatmap-changing column or row names

Moreno Ignazio Coco M.I.Coco at sms.ed.ac.uk
Wed May 28 18:55:30 CEST 2008


Dear R Community,

I am trying to create an heatmap for the following set of data:

##example of data matrix
o4
        V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
green  27 28 29 29 28 28 26 25 25  23  23  22  22  21  21  22  22  22
yellow  6  8  8  7  7  7  6  6  6   7   7   7   6   6   6   6   6   5
red    15 15 15 15 15 15 14 13 12  11  12  10   9   8   7   6   8   9
pink   11 11 11 11 11 10 12 11 13  14  14  15  15  14  14  17  17  17
blue   17 15 15 16 17 17 17 17 18  18  18  19  20  20  20  21  22  21

the column names are timepoints 450 in total. When I run the heatmap code:

x  <- as.matrix(o4)
ramp <- colorRamp(c("yellow","green","blue"))
cv<-rgb( ramp(seq(0, 1, length = 83)), max = 255)

heatmap(x, col = cv, Colv=NA, Rowv=NA,xaxt="n", yaxt="n",
scale="column", margins=c(5,10), labCol=NA,xlab = "Time", ylab= "Colors",
main = "")

I have quite few problems to change the column names. Being 450  
timepoints too many to be readable on the plot, I wanted to  
reduce/scale them to, let say 45. So, as you can see from the code  
above, I have removed the x and y, row and column information.
Then I have tried to create a new name vector:

##create col vector to add names

Colname<-as.character(seq(0,4500,500))

##putting it as arguments of (labCol=Colname, in the heatmap function)

but this solution didn't work. It looks like as it cannot find the  
exact point on the axis where to stick the label in and it clutters  
all the datapoint on the same spot without being able to unfold it.

Therefore I have tried to introduce an axis:

axis(1, at=seq(0,450,1),line=1)

and then adding some text on top

mtext(paste(seq(0,4500, 250),sep=""),side=1,  
at=seq(0,450,25),line=2,cex=0.6,las=1)

also this way didn't work out. Actually, it has created a kind of axis  
but the zero of it was aligned to the middle of the plot. So, it was  
completely shifted.
That was my first problem.

Second small problem.
I am trying to mark on the heatmap some crucial timepoints. I wanted  
to do it by adding a straight abline on the heatmap plot

abline(v=80,col=green)

but also this doesn't seem to have any result
It seems that it is quite difficult to add any information to the  
heatmap, but perhaps some of you might know how to do it.

Many thanks in advance

Moreno




-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



More information about the R-help mailing list