0

I am using gplots and Rcolorbrewer to make a heatmap using the heatmap2() function.
My data has zeros denoting that no data is recorded in this samples. To create the heatmap, I want these zeros to be coloured white and the rest above in a three colour legend.

Here is the code so far:

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")
Joe
  • 8,073
  • 1
  • 52
  • 58
Epilotus
  • 31
  • 2
  • 7

1 Answers1

0

As commented, replace zeros with NAs like so:

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

Now rerun the heatmap, adding 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")
Joe
  • 8,073
  • 1
  • 52
  • 58
  • I am having an issue now that seems to be a difficult one to solve by what I read on other posts. I now get the following message: Error in hclustfun(distr) : NA/NaN/Inf in foreign function call (arg 11) – Epilotus Feb 22 '17 at 20:40