Question: giving a color to null values on heatmap2
0
gravatar for demoraesdiogo2017
9 months ago by
demoraesdiogo201710 wrote:

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?

nas heatmap null values • 987 views
ADD COMMENTlink modified 9 months ago by dariober10k • written 9 months ago by demoraesdiogo201710
1

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

ADD REPLYlink written 9 months ago by RamRS22k
3
gravatar for dariober
9 months ago by
dariober10k
WCIP | Glasgow | UK
dariober10k wrote:

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 COMMENTlink written 9 months ago by dariober10k

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 REPLYlink written 9 months ago by Kevin Blighe45k

heatmap function in complexheatmap takes na_col for NA color.

ADD REPLYlink written 9 months ago by cpad011211k
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 REPLYlink written 9 months ago by demoraesdiogo201710

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 REPLYlink written 9 months ago by RamRS22k
2
gravatar for jomo018
9 months ago by
jomo018480
jomo018480 wrote:

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 COMMENTlink written 9 months ago by jomo018480
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 888 users visited in the last hour