Created
December 12, 2022 06:56
-
-
Save Deleetdk/1c65a68567be7c8c2b59a7ba63c7d43a to your computer and use it in GitHub Desktop.
pairwise correlation with crosses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(kirkegaard) | |
#get cors with p values | |
cors = iris[-5] %>% | |
wtd.cor() | |
cors = mpg[map_lgl(mpg, is.numeric)] %>% | |
wtd.cor() | |
#long format | |
cors_to_long = function(x, remove_lower = T, remove_diag = T) { | |
#remove as needed | |
if (remove_lower) x[lower.tri(x)] = NA | |
if (remove_diag) diag(x) = NA | |
#add var names | |
bind_cols( | |
value = as.numeric(x), | |
expand_grid( | |
Var2 = rownames(x), | |
Var1 = colnames(x) | |
) | |
) %>% filter(!is.na(value)) | |
} | |
cor_mat_long = cors_to_long(cors$correlation) | |
cor_mat_p_long = cors_to_long(cors$p.value) | |
cor_mat %>% | |
GG_heatmap(reorder_vars = F) + | |
geom_text(data = cor_mat_p_long %>% filter(value > .05), aes(label = "X"), alpha = .2, size = 10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment