1

I'm trying to generate a simple heatmap that has each row and column separated by a black line. However, for some reason this only happens for the first and last color. The middle color in my colorpanel() command has an addition horizontal and vertical line that I would like to get rid off when plotted using heatmap.2(). Any suggestions as to why I see these lines?

library(gplots)

my.matrix <- cbind(func.1 = c(1,2,2,1,1,3,1,2,3,1,1,2,2,3,1), func.2 =
c(2,2,1,1,3,3,1,1,2,2,1,3,3,2,1))

mycol <- colorpanel(n=3,"green","grey","red")

heatmap.2(my.matrix,Rowv=FALSE, Colv="Rowv", col=mycol, trace="both",
tracecol="black", key=FALSE, symm=FALSE, vline=NULL, hline=NULL)

link to the plot I get: https://dl.dropbox.com/u/8900971/heatmap.png

user1974415
  • 13
  • 1
  • 4
  • heatmap.2() and colorpanel() are in the gplots package – user1974415 Jan 13 '13 at 17:03
  • @user1974415 what if use `trace="row"` and a line in the middle? – agstudy Jan 13 '13 at 18:10
  • trace="row" does not solve the problem – user1974415 Jan 13 '13 at 18:19
  • @user1974415 Please use `?heatmap.2` and look this one up. agstudy pointed you where to look but do some leg work on your own. – Tyler Rinker Jan 13 '13 at 18:50
  • I did look it up... as well as trying the new code in R. But changing the trace argument in heatmap.2 to "row" still does not remove the horizontal line in the center of all grey cells. The part I don't understand is why only some colored cells have this horizontal line – user1974415 Jan 13 '13 at 19:14

1 Answers1

1

There's probably a way to do what you want but when I read your last comment my mind went to ggplot2. You didn't say it has to be a heatmap.2 solution so here's a ggplot2 one. Though I'm assuming the gplots version is of mor interest:

library(reshape2, ggplot2)
dat <- melt(my.matrix)

ggplot(dat, aes(x=Var2,y=Var1))+ 
    geom_tile(aes(fill = value),colour='black') +
    scale_fill_gradientn(colours=c("green","gray","red"),
    values  = rescale(c(min(dat$value), 1000, max(dat$value)))) +
    coord_equal() 
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
  • no, heatmap.2 is not key. Many thanks for a very good alternative solution (which also motivates me to read more about ggplot2) – user1974415 Jan 13 '13 at 21:05