heatmap.2 (gplots package) - how to remove annoying lines in some cells?

感情迁移 提交于 2019-12-08 08:10:44

问题


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


回答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() 


来源:https://stackoverflow.com/questions/14305448/heatmap-2-gplots-package-how-to-remove-annoying-lines-in-some-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!