kirkegaard
kirkegaard copied to clipboard
GG_heatmap(): fails with NAs in correlation matrix
Can happen when there's rare event data, or missing pairwise data.
> #plot
> mh_cors$correlations %>%
+ GG_heatmap(color_label = "Latent\ncorrelation",
+ font_size = 1) +
+ theme(axis.text.x = element_text(size = 7)) +
+ ggtitle("Medical history heatmap")
Error in hclust(dd) : NA/NaN/Inf in foreign function call (arg 10)
Reprex
> iris_cor = cor(iris[-5])
> iris_cor
Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length 1.000 -0.118 0.872 0.818
Sepal.Width -0.118 1.000 -0.428 -0.366
Petal.Length 0.872 -0.428 1.000 0.963
Petal.Width 0.818 -0.366 0.963 1.000
> iris_cor[2, 1] = NA
> iris_cor[1, 2] = NA
> iris_cor
Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length 1.000 NA 0.872 0.818
Sepal.Width NA 1.000 -0.428 -0.366
Petal.Length 0.872 -0.428 1.000 0.963
Petal.Width 0.818 -0.366 0.963 1.000
> iris_cor %>% GG_heatmap()
Error in hclust(dd) : NA/NaN/Inf in foreign function call (arg 10)
Seems difficult to do anything about, however.