I am following the documentation on https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html to create a heatmap with NAs. The documentation says that the Heatmap() function can cluster data with NA. However, I am getting an error about hclust complaining about NA in the data.
Here is my dataset: https://drive.google.com/file/d/1Wm-CUir57-eYnb0EnSxNLzKcTyLlj5Ux/view?usp=sharing
library(ComplexHeatmap)
# I did this to prepare the input matrix.
na_index = sample(c(TRUE, FALSE), nrow(in_mat)*ncol(in_mat), replace = TRUE, prob = c(1, 9))
in_mat[na_index] = NA
# And this to plot the heatmap.
ht <- Heatmap(in_mat, column_dend_side = "bottom",
column_dend_height = unit(3, "cm"),
column_dend_reorder = TRUE,
column_split = 10,
na_col = "black")
png(file.path(figures_folder, "hclust_heatmap_sig_only.png"), width = 30, height = 10, units = "in", res = 300)
draw(ht)
dev.off()
I am getting this error when I am saving the plot.
Error in hclust(get_dist(t(mat), distance), method = method) :
NA/NaN/Inf in foreign function call (arg 10)
The error goes away if I replace NAs with zeros or switch off clustering.
I want to plot a heatmap with clustering on both rows and columns and split the columns or rows in K groups. I want to keep NAs in the data. Any suggestions would be helpful. Thanks.