I'm currently working on a heatmap that uses a complex discrete color scale (about 34 different colors). Some of the colors are dark while others are light. I'm labeling cells with the cellnote
argument of the heatmap.2()
function. Since some of the background colors of the cells are very dark, when using a black cellnote color the cell labels can't be seen. Likewise, when using a lighter cellnote color the labels in the cells with a light background color can't be seen. Was wondering if it is possible to have different cellnote colors in a single heatmap produced with the ´heatmap.2()´ function. Here is a small example of the situation:
library(gplots)
x <- cbind(c(0.5, 1.5), c(1.5, 0.5))
pal <- c("darkblue", "lightblue")
heatmap.2(
x,
Rowv = FALSE,
Colv = FALSE,
dendrogram = "none",
key = FALSE,
trace = "none",
col = pal,
breaks = seq(0, 2),
cellnote = x,
notecol = "black",
notecex = 2
)
The desired output would be to have white cellnote in the upper-left and down-right cells while keeping a black cellnote in the other cells. I anticipate this will potentially require to modify the function's source code. However, I haven't been able to come up with a solution myself.