I am trying to make a correlation plot with a subset of variables versus a different subset.
Using the mtcars
data I do the following using ggcorrplot
:
data(mtcars)
corrtest <- psych::corr.test(mtcars[,1:7], adjust="none")
all_matrix <- corrtest$r
all_pmat <- corrtest$p
pheno_markers <- names(mtcars)[1:4]
serol_markers <- names(mtcars)[5:7]
sub_matrix <- all_matrix[pheno_markers, serol_markers]
sub_pmat <- all_pmat[pheno_markers, serol_markers]
grDevices::pdf(file="heat_duo.pdf", height=4, width=4)
print(
ggcorrplot::ggcorrplot(sub_matrix, p.mat=sub_pmat, method="circle")
)
grDevices::dev.off()
This produces the following plot, which is good:
Now I want to reproduce the same plot with ggcorrplot2
instead, cause it allows me to overlay significance values of the comparisons as ***
. I use this package usually with no problem, but I do not seem to get this case right; it seems it can only deal with symmetrical matrices with colnames
== rownames
...
I tried the following:
grDevices::pdf(file="heat_duo2.pdf", height=4, width=4)
print(
ggcorrplot2::ggcorrplot(sub_matrix, p.mat=sub_pmat, method="circle",
insig = "label_sig", sig.lvl = c(0.05, 0.01, 0.001))
)
grDevices::dev.off()
But the result is obviously wrong:
Any idea on how to deal with a case like this in ggcorrplot2
(ggcorrplot
makes it so easy)?