R ComplexHeatmap:使用NAs绘制和群集热图

R ComplexHeatmap:使用NAs绘制和群集热图,r,heatmap,missing-data,hclust,R,Heatmap,Missing Data,Hclust,我正在按照上的文档创建NAs热图。文档中说Heatmap()函数可以使用NA对数据进行聚类。然而,我得到了一个关于hclust的错误,它抱怨数据中的NA 这是我的数据集: 如果我用零替换NAs或关闭群集,错误就会消失 我想在行和列上绘制一个具有集群的热图,并将列或行拆分为K组。我想在数据中保留NAs。任何建议都会有帮助。谢谢 library(ComplexHeatmap) # I did this to prepare the input matrix. na_index = sample(c(

我正在按照上的文档创建NAs热图。文档中说Heatmap()函数可以使用NA对数据进行聚类。然而,我得到了一个关于hclust的错误,它抱怨数据中的NA

这是我的数据集:

如果我用零替换NAs或关闭群集,错误就会消失

我想在行和列上绘制一个具有集群的热图,并将列或行拆分为K组。我想在数据中保留NAs。任何建议都会有帮助。谢谢

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()
Error in hclust(get_dist(t(mat), distance), method = method) :
NA/NaN/Inf in foreign function call (arg 10)