Pregunta

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

¿Fue útil?

Solución

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() 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top