在heatmap2中保持零值为无值

时间:2017-01-10 03:02:08

标签: r heatmap gplots

我正在使用gplotsRcolorbrewer使用heatmap2()功能制作热图。
我的数据有零表示此样本中没有记录数据。要创建热图,我希望这些零颜色为白色,其余部分为三色图例。

以下是目前的代码:

my_palette <- colorRampPalette(c("blue", "green", "red"))(n = 299)
col_breaks = c(seq(0.001,0.2,length=100), seq(0.3,0.4,length=100), seq(0.5,0.6,length=100))

library(gplots)
heatmap.2(deco.hmBB, main = "BCC at day 0 and day 10", margins = c(6,9), trace = "none", 
density.info = "none", dendrogram = "none", col = my_palette,  breaks =  col_breaks, 
Colv = "NA")

1 个答案:

答案 0 :(得分:0)

如评论所述,用NA代替零:

deco.hmBB[deco.hmBB == 0] <- NA

现在重新运行热图,添加na.color

heatmap.2(deco.hmBB, main = "BCC at day 0 and day 10", margins = c(6,9),
trace = "none", density.info = "none", dendrogram = "none", 
col = my_palette, breaks = col_breaks, Colv = "NA", na.color = "White")