Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recenter heatmap.2 in R

Tags:

r

heatmap

I used following code to generate a heatmap using heatmap.2 of R. key="F" gets rid of color key at the top. However the plot does not rescale leaving a blank space on the place previously occupied by the colour key. How do I recenter the plot by getting rid of the blank space at the top?

dImp_heatmap <- heatmap.2(dSet_matrix, Rowv=NA, Colv=NA, col = cm.colors(20), dendrogram="none",trace="none", key="F",margins=c(1,8),colsep=c(1:6),rowsep=(1:62),sepwidth=c(0.05,0.05), sepcolor="white", cellnote=round(dSet_matrix,digits=2),notecol="black",notecex=0.7,scale="column")
like image 526
lochi Avatar asked Mar 19 '12 20:03

lochi


1 Answers

If you read the documentation for ?heatplot.2 carefully, you'll see at the bottom of the list of arguments the following:

lmat, lhei, lwid visual layout: position matrix, column height, column width. See below for details

And the details are:

This layout can be overriden by specifiying appropriate values for lmat, lwid, and lhei. lmat controls the relative postition of each element, while lwid controls the column width, and lhei controls the row height. See the help page for layout for details on how to use these arguments.

So for example:

data(mtcars)
 x  <- as.matrix(mtcars)
 rc <- rainbow(nrow(x), start=0, end=.3)
 cc <- rainbow(ncol(x), start=0, end=.3)

 ##
 ## demonstrate the effect of row and column dendrogram options
 ##
 gplots:::heatmap.2(x,key = FALSE,dendrogram = "row",lhei = c(0.05,0.95))

enter image description here

and I imagine the setting lwid would behave similarly. Although I should add that if you include both dendrograms, then the space in the upper left is necessary to make room for the dendrograms.

like image 142
joran Avatar answered Nov 12 '22 01:11

joran