Handle missing values in the z-score matrix while plotting heatmap in the ComplexHeatmap
1
0
Entering edit mode
@mohammedtoufiq91-17679
Last seen 25 days ago
Qatar

Hi,

I have a data matrix with the missing values "NA" in between for some of the genes, I converted to a z-score data matrix in order to plot the heatmap . However, while plotting the heatmap in the ComplexHeatmap package in R, i get error message as below. Is there a way to handle missing values in the ComplexHeatmap package to avoid this error and to be able to plot on the z-score matrix. I understand that, na_col = "grey" could be used to color "NA". How can I pass the z-score matrix in the Heatmap.

Blockquote

NA/NaN/Inf

Blockquote

Thank you, Toufiq

matrix heatmap ComplexHeatmap missing values R • 945 views
1
Entering edit mode
Zuguang Gu ▴ 210
@zuguang-gu-7797
Last seen 6 days ago
Germany / Heidelberg / DKFZ

try:

m2 = t(apply(m, 1, function(x) (x - mean(x, na.rm = TRUE))/sd(x, na.rm = TRUE)))
Heatmap(m2)

0
Entering edit mode

Thank you Zuguang,

I have a question,

Blockquote

ms = t(apply(m, 1, function(x) (x - mean(x, na.rm = TRUE))/sd(x, na.rm = TRUE)))

Here, I understand, "x" is my data matrix with missing values (NA) and what is "m"?

Can I also use the below code?

Blockquote

for(i in 1: nrow(my_matrix))

{

mymatrixZ[i,]<- (mymatrix[i,]-mean(mymatrix[i,], na.rm = TRUE))/sd(my_matrix[i,], na.rm = TRUE)

}

1
Entering edit mode

m is your matrix (your mat_marix). What you did in the for loop basically is the same as the apply() function.

0
Entering edit mode

Thank you Zuguang. It was helpful.

0
Entering edit mode

hi,Zuguang, I have same question about Z-score and plot Heatmap using ComplexHeatmap. my data is like this :

Symbol  wt  sample      Symbol  scaled_wt   scaled_sample
gene1   0   2.37881265      gene1  -0.7071068  0.7071068
gene2   5.966551319 4.099313307     gene2   0.7071068 -0.7071068
gene3   5.644581511 4.152978583     gene3   0.7071068 -0.7071068
gene4   11.98032295 6.664492914     gene4   0.7071068 -0.7071068
gene5   4.724087877 6.500925531     gene5  -0.7071068  0.7071068
gene6   5.659375142 4.05156459      gene6   0.7071068 -0.7071068
gene7   6.41069746  5.358651504     gene7   0.7071068 -0.7071068
gene8   5.170742633 3.207399694     gene8   0.7071068 -0.7071068
gene9   13.15710834 13.26952889     gene9  -0.7071068  0.7071068
gene10  11.24848427 11.03365414     gene10  0.7071068 -0.7071068
gene11  9.213433903 9.039837481     gene11  0.7071068 -0.7071068
gene12  12.05076217 12.31615003     gene12 -0.7071068  0.7071068
gene13  13.19975925 13.22039108     gene13 -0.7071068  0.7071068
gene14  11.75079093 11.85547733     gene14 -0.7071068  0.7071068


I know gene1-8 is difference.what I want to do is that i want to view the difference by Complexheatmap,maybe gene9 number is so big that the color range is very big and in order that some different genes like that gene1 color is not obvious.After I scaled my data by your above method,scaledwt,scaledsample,these number is same,why? help me.

thank you very much!!

1
Entering edit mode

It is because, for each gene, you only have two values.

0
Entering edit mode

thank you Zugaung!