text: user2531: I am making a heatmap using RNA-Seq data in R. The heatmap shows gene expression values (RPKM) in different brain regions. I have the following code:
  library(tidyverse)
  
  library(pheatmap)
  
  library(matrixStats)
  
  read_csv("prenatal_heatmap_data.csv") -> all_data
  
  all_data %>%
  
     column_to_rownames("Brain Region") -> heatmap_data
  
  heatmap_data %>%
  
     pheatmap()
  
  Which generates the following heatmap:
  I want to do a log2 transformation of the RPKM values so that I can do the Z-score standardisation of the data. I have log2-transformed the values using the following code:
  heatmap_data %>%
  
     log2() -> heatmap_data_log2
  
  heatmap_data_log2 %>%
  
     pheatmap()
  
  However, when I try to create a heatmap using the log2-transformed values I get the following error:
  
  I have looked at the log2-transformed data and I know that the reason I am getting this error is because in the original dataset, some of the RPKM values were 0. When these 0 values get log-transformed they become -Inf:
  
  ^ Original Data
  
  ^ log2 transformed data
  I am not sure how to overcome this issue. I was wondering if it is necessary to do the log2 transformation of the RPKM values before doing the Z-score standardisation? I have seen that it is conventional to do the log2-transformation of the data.
  Any advice is appreciated.
  
  user-1: Add a pseudocount of one as in the code suggestion I gave you earlier: Best methods for clustering heatmap based on regions where the genes are most highly expressed?
  Log of zero is not defined.
  
original_text: 2531: <p>I am making a heatmap using RNA-Seq data in R. The heatmap shows gene expression values (RPKM) in different brain regions. I have the following code:</p>
  <pre><code>library(tidyverse)
  
  library(pheatmap)
  
  library(matrixStats)
  
  read_csv(&quot;prenatal_heatmap_data.csv&quot;) -&gt; all_data
  
  all_data %&gt;%
  
     column_to_rownames(&quot;Brain Region&quot;) -&gt; heatmap_data
  
  heatmap_data %&gt;%
  
     pheatmap()
  </code></pre>
  <p>Which generates the following heatmap:</p>
  <p>I want to do a log2 transformation of the RPKM values so that I can do the Z-score standardisation of the data. I have log2-transformed the values using the following code:</p>
  <pre><code>heatmap_data %&gt;%
  
     log2() -&gt; heatmap_data_log2
  
  heatmap_data_log2 %&gt;%
  
     pheatmap()
  </code></pre>
  <p>However, when I try to create a heatmap using the log2-transformed values I get the following error:</p>
  <p><a href="https://i.stack.imgur.com/ixnfd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ixnfd.png" alt="enter image description here" /></a></p>
  <p>I have looked at the log2-transformed data and I know that the reason I am getting this error is because in the original dataset, some of the RPKM values were 0. When these 0 values get log-transformed they become -Inf:</p>
  <p><a href="https://i.stack.imgur.com/hT7l7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hT7l7.png" alt="Original Data" /></a></p>
  <p>^ Original Data</p>
  <p><a href="https://i.stack.imgur.com/MJ0B7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MJ0B7.png" alt="enter image description here" /></a></p>
  <p>^ log2 transformed data</p>
  <p>I am not sure how to overcome this issue. I was wondering if it is necessary to do the log2 transformation of the RPKM values before doing the Z-score standardisation? I have seen that it is conventional to do the log2-transformation of the data.</p>
  <p>Any advice is appreciated.</p>
   -1: <p>Add a pseudocount of one as in the code suggestion I gave you earlier: <a href="https://bioinformatics.stackexchange.com/questions/18251/best-methods-for-clustering-heatmap-based-on-regions-where-the-genes-are-most-hi">Best methods for clustering heatmap based on regions where the genes are most highly expressed?</a></p>
  <p>Log of zero is not defined.</p>
  