Question: Handle missing values in the z-score matrix while plotting heatmap in the ComplexHeatmap
0
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

Answer: Handle missing values in the z-score matrix while plotting heatmap in the Comple
1
Zuguang Gu170 wrote:

try:

m2 = t(apply(m, 1, function(x) (x - mean(x, na.rm = TRUE))/sd(x, na.rm = TRUE)))
Heatmap(m2)
ADD COMMENTlink modified 4 weeks ago • written 4 weeks ago by Zuguang Gu170

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)

}

ADD REPLYlink modified 4 weeks ago • written 4 weeks ago by mohammedtoufiq910
1

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