How to plot a correlation controlling for a third variable in ggplot2 ? R

Viewed 53

I'm used to ggpubr to plot correlations in ggplot2, along with stats_smooth(method = lm) but I'm wondering how can I plot a partial correlation?

This is what I do for a canonical corr:

stat_smooth(formula = y ~ x, method = lm, color = "blue", se=F) +

stat_cor(aes(label =paste(label, cut(..p.., 
                                           breaks = c(-Inf, 0.0001, 0.001, 0.01, 0.05, Inf),
                                           labels = c("'***'", "'***'", "'**'", "'*'", "'ns'")), 
                                sep = "~")), method="pearson", cor.coef.name = c("r"), 
   

but now I have a partial correlation, such as:

ppcor::

pcor.test(x, y, z, method = c("pearson", "kendall", "spearman"))

pcor.test(data$X1,data$X2,
          data$Z method = "pearson")

Any thoughts would be much appreciated! I've seen some suggestions here, but not with ggplot2...
I've seen this and this, but I still can't plot it. Thanks in advance!!!

Obs: All variables are continuos

0 Answers
Related