I usually provide a simple correlation matrix plot as the output of correlation analyses using psych::corr.test
and corrplot
.
Now I am required to accompany it by a more detailed matrix plot with densities and scatter plots with slopes, for colleagues to be able to interpret the original plot better.
For this latter purpose I use GGally::ggpairs
, which gives me all I need. My problem here is that I do not seem to be able to specify the exact same details I do with psych::corr.test
and corrplot
...
See my MWE with mtcars
:
I first generate my correlation and pvalue matrices using Pearson's correlation and BH for adjusting.
data(mtcars)
mtcars
correlation_result <- psych::corr.test(mtcars[,1:7], method="pearson", adjust=mymethod, alpha=.05)
correlation_matrix <- correlation_result$r
pvalue_matrix <- correlation_result$p
I then produce my original simple plot; I just want to show *
and **
for p-values lower than 0.05 and 0.01 respectively:
#1
grDevices::pdf(file="test1.pdf", height=10, width=10)
corrplot::corrplot(correlation_matrix, p.mat=pvalue_matrix, sig.level=c(0.01, 0.05), method="circle", type="upper",
insig="label_sig", pch.cex=2, order="original", pch.col="white", tl.col="black",
tl.pos="td", tl.cex=2, cl.cex=2, diag=FALSE, mar=c(0,0,2,2))
grDevices::dev.off()
I get this plot, which is exactly what I need:
Finally, I make my detailed plot with GGally::ggpairs
, but there are a couple of details I cannot specify:
- While I can specify Pearson's correlation, there is no
adjust
parameter for BH p-value adjust - The asterisks shown just follow the following criteria, and I do not seem to be able to change it with the
stars
parameter:***
if the p-value is < 0.001,**
if the p-value is < 0.01,*
if the p-value is < 0.05,.
if the p-value is < 0.10
I use this code:
#2
grDevices::pdf(file="test2.pdf", height=15, width=15)
print(
GGally::ggpairs(mtcars, columns=1:7,
lower=list(continuous=GGally::wrap("smooth", alpha=0.5, size=3)),
diag=list(continuous=GGally::wrap("densityDiag", alpha=0.5)),
upper=list(continuous=GGally::wrap("cor", method="pearson", stars=TRUE, size=6))) +
ggplot2::theme_light() +
ggplot2::theme(axis.text=ggplot2::element_text(size=15),
strip.text=ggplot2::element_text(size=20,face="bold"))
)
grDevices::dev.off()
This produces the following plot:
Aesthetically it is exactly what I need, but the significance shown does not match my original plot... I want to be able to adjust the p-values, and show significance for just my 2 cutoffs of 0.05 and 0.01... is there any way to do it (preferably with GGally::ggpairs
)?