giving a color to null values on heatmap2
2
0
Entering edit mode
6.1 years ago

Hello

I'm using the following code to generate a heatmap for my data, like this

library(gplots)
getwd()
row.names(fold_change_cuttoff_at_2_cuttoff_at_2) <- fold_change_cuttoff_at_2$Gene
y <-data.matrix(fold_change_cuttoff_at_2)
y <- y[1:2162, 2:13]
y
?heatmap.2
??heatmap.2
heatmap.2(y, main = "Secretome Profile", trace ="none", margins = c(10,12))
yb <- colorRampPalette(c("white","yellow","orange","darkorange","red","darkred","black"))(n = 299)
heatmap.2(y, col=yb, main = "Secretome Profile", trace ="none", margins = c(5,15), cexRow = 0.7)

However, because I have many null values (some genes appear as differentially expressed in some tumors, but not others) I get a pretty weird looking heatmap, as I replaced NAs with 0s. So, is there anyway to generate a heatmap anyway, but with the NAs as, say, gray?

heatmap null values nas • 12k views
ADD COMMENT
1
Entering edit mode

I do this by replacing NA with "NA" and assigning a color to "NA". Maybe there's a better way?

ADD REPLY
4
Entering edit mode
6.1 years ago

I haven't tried it, but heatmap.2 takes the argument na.color which should suite you: Color to use for missing value (NA). Defaults to the plot background color.

(How can you have missed it? heatmap.2 takes only 59 arguments!)

ADD COMMENT
0
Entering edit mode

Yes, I have noticed that heatmap.2 is still under development. I looked at the parameters yesterday and there are many more than when I first began to use it ~10 years ago. It is still not at the breadth of features of ComplexHeatmap, though.

ADD REPLY
0
Entering edit mode

heatmap function in complexheatmap takes na_col for NA color.

ADD REPLY
0
Entering edit mode
heatmap.2(y, col=yb, main = "Secretome Profile", trace ="none", na.color="gray", margins = c(5,15), cexRow = 0.7)

Thank you for the help. I tried used the argument in the code above, but when I run it, it gives me the following error message:

Error in hclustfun(distr) : NA/NaN/Inf in foreign function call (arg 11)

So I have no idea what to do

ADD REPLY
0
Entering edit mode

NA/NaN/Inf in foreign function call

Try googling the error message. It is pretty specific and will give you leads on what to look for in your data.

ADD REPLY
2
Entering edit mode
6.1 years ago
jomo018 ▴ 730

You can use heatmap.2 breaks parameter to map between your 299 color shades and your fold-change values. Next assign NA to an "unused" figure (either larger than your maximum fold change or, in your case, possibly lower than your limit of 2). Finally, map this NA-figure to gray.

In my experience, the visual outcome is weird as well although scientifically more accurate.

ADD COMMENT

Login before adding your answer.

Traffic: 1737 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6