ropensci / iheatmapr

Complex, interactive heatmaps in R
https://docs.ropensci.org/iheatmapr
Other
267 stars 36 forks source link

Support missing values in continuous annotations #55

Open ahmohamed opened 5 years ago

ahmohamed commented 5 years ago

First of all, thanks a lot for this awesome package.

Currently, plotting fails with an ambiguous message if row/col annotation is continuous and contains missing values:

library(iheatmapr)
library(datasets)
library(reshape2)

Indometh_matrix <- acast(Indometh, Subject ~ time, value.var = "conc")
Indometh_matrix <- Indometh_matrix[as.character(1:6),]
rownames(Indometh_matrix) <- paste("Patient",rownames(Indometh_matrix))
Indometh_patient_cor <- cor(t(Indometh_matrix))

patient_max_conc <- apply(Indometh_matrix,1,max)
patient_min_conc <- apply(Indometh_matrix,1,min)
patient_groups <- c("A","A","B","A","B","A") # Arbitrary groups

patient_max_conc[[1]] <- NA

iheatmap(Indometh_patient_cor, 
  row_annotation = data.frame("Max" = patient_max_conc))

# Error in if (diverging) { : missing value where TRUE/FALSE needed

The issue stems from these lines not using na.rm=TRUE https://github.com/ropensci/iheatmapr/blob/b9fd1bc2bdbbfdd1084619dfd85fb7480b2ff4f7/R/annotations.R#L70-L73

https://github.com/ropensci/iheatmapr/blob/b9fd1bc2bdbbfdd1084619dfd85fb7480b2ff4f7/R/annotations.R#L161-L164

Alternatively, you can modify pick_conitnuous_colors to accommodate diverging=NA.

Cheers.

AliciaSchep commented 5 years ago

Thanks for bringing up the issue and identifying the code responsible -- have now put in a PR with a fix for this!