0

I tried to generate a heatmap using heatmap.2 in gplots package. My aim is to generate a heatmap with no extra space between plot area and heatmap (excluding the key at the bottom). By looking at some posts, I managed to fit heatmap to plot area using lmat (so that there are no space at left part). But I cannot center the color key below the plot. As a result, there is some space because of the projected a color scale scale at the right side. Can anyone tell me how to make the color key at the center of the heatmap at bottom part (thus to avoid extra space problem). I am unable to show the image. I use following code to generate heatmap.

library(gplots)
dat <- read.csv("C:..../xxx.csv")
dat_matrix <- data.matrix(dat)
colors = c(seq(-2,-1,length=100),seq(-1,1,length=100),seq(1,2,length=100))
my_palette <- colorRampPalette(c("green","black","red"))(n = 299)
lmat = rbind(c(1,3),c(2,1),c(1,4))
lwid = c(1,4)
lhei = c(1,4,1.2)
heatmap.2(dat_matrix, dendrogram="none", Rowv = FALSE, Colv = FALSE,
          col = my_palette, breaks = colors, scale = "none", key = TRUE,
          density.info = "none", trace = "none", labRow = FALSE, symm = FALSE,
          symkey = TRUE, symbreaks = TRUE, lmat = lmat, lwid = lwid, lhei = lhei)
Henrik
  • 65,555
  • 14
  • 143
  • 159
Seowoo Kim
  • 85
  • 9
  • 1
    Please make it easier for people to help you by providing a [**self contained example**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). E.g., use data from the first example in `?heatmap.2`. – Henrik Jan 07 '15 at 10:01

1 Answers1

0

You can use the parameter key.par and set the mar to something suitable. For example using dat_matrix <- as.matrix(mtcars) and otherwise your data, I used mar=c(8,0,0,12). You'll have to figure out what mar best fits your data.

heatmap.2(dat_matrix, 
          dendrogram="none", 
          Rowv=FALSE, 
          Colv=FALSE, 
          col = my_palette, 
          breaks=colors,      
          scale="none", 
          key=TRUE, 
          key.par = list(mar= c(8, 0, 0, 12)),
          density.info="none", 
          trace="none", 
          labRow=FALSE, 
          symm=F,
          symkey=T,
          symbreaks=T, 
          lmat = lmat, 
          lwid = lwid, 
          lhei = lhei)
shadow
  • 21,823
  • 4
  • 63
  • 77