Question: Handle missing values in the z-score matrix while plotting heatmap in the ComplexHeatmap
0
4 weeks ago by
mohammedtoufiq910 wrote:

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

modified 4 weeks ago by Zuguang Gu170 • written 4 weeks ago by mohammedtoufiq910
Answer: Handle missing values in the z-score matrix while plotting heatmap in the Comple
1
4 weeks ago by
Zuguang Gu170
Germany / Heidelberg / DKFZ
Zuguang Gu170 wrote:

try:

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


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

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