0

I am trying to create a genus level heatmap for microbial community identified in my samples. The abundance ranges from 0 to 1. I would like to log-transform the abundance for better visualizing. However, I concern that the log(0), which indicates the absence of bacteria, will not be able to be visualized. I am trying to color these blanks (undefined log values or Inf values) on my heatmap, but I struggle to figure out how to do it.

My data frame is:

Gene    Sample      Abundance      Log10.abundance
A          1          0.0186        -1.7306
B          2            0             -Inf
C          3         7.79E-06       -5.108
D          4          0.0031        -2.5103
E          5            0             -Inf
...       ...         ...              ...

My code was:

ggplot(data=heatmap, mapping=aes(x= Sample, y= Gene,fill= Log10.abundance)) + 
geom_tile() +
xlab(label = "Sample") + 
scale_fill_distiller(name = "Log10(Abundance)", palette = "RdYlGn")

I greatly appreciate if you could have any help to resolve this problem!

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Lian
  • 1
  • 1
  • Please add your code and a [reproducible example](https://stackoverflow.com/a/5963610/11570343) using `dput()` – cdcarrion Sep 17 '20 at 05:48
  • 1
    log(0) is -Inf. You could replace -Inf with NA. ggplot will then show this in grey. – Richard Telford Sep 17 '20 at 06:58
  • @RichardTelford Thank you very much for your suggestion. However, do you know how to change the grey color as this color was hard to distinguish from dark blue? – Lian Sep 19 '20 at 19:25
  • https://stackoverflow.com/questions/6906661/ggplot2-make-missing-value-in-geom-tile-not-blank – StupidWolf Sep 19 '20 at 20:24

0 Answers0