<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.sstatic.net/ixnfd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/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.sstatic.net/hT7l7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hT7l7.png" alt="Original Data" /></a></p>
<p>^ Original Data</p>
<p><a href="https://i.sstatic.net/MJ0B7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/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>

CC BY-SA 4.0
2022-02-09T14:46:32.743Z
Nice questions. Please remember to upvote an accepted answer
M__
<r><heatmap>
RNA-Seq Data Heatmap: Is it necessary to do a log2 transformation of RPKM values before doing the Z-score standardisation?
# RNA-Seq Data Heatmap: Is it necessary to do a log2 transformation of RPKM values before doing the Z-score standardisation?

(Asked by: username_0 on 2022-01-03)

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.

**Tags:** r, heatmap
> **Comments:**
> **username_1**: Nice questions. Please remember to upvote an accepted answer  

---

## 0 answers

