Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggcorrplot: insignificant values

I've created a corrplot using ggcorrplot with the following code:

library(ggcorrplot)

corCN <- subset(csfBL, BL_Diaggroups==1, 
                select=c("log_ab38", "log_ab40", "log_ab42", "ABratio", "log_YKL", "logNgcomplete", "log_NFL"))

colnames(corCN) <- c("Aß 1-38","Aß 1-40", "Aß 1-42", "Aß 42/40", "YKL-40", "Ng", "NFL")

corrCN <- cor(corCN, method=c("spearman"), use="complete.obs")
p.matCN <- cor_pmat(corCN, method=c("spearman"), use="complete.obs")

CNcorrplot <- ggcorrplot(corrCN, type="lower", lab=TRUE, ggtheme = ggplot2::theme_classic,
                          p.mat=p.matCN, insig ="blank")

CNcorrplot2 <- CNcorrplot + ggtitle("CN") + theme(plot.title = element_text(hjust = 0.5)) 

And the plot looks like this.

Corrplot

The only thing I want to change is that the insignificant values have "NS" in them or are totally blank (so no 0 displayed). Actually I would need some kind of code saying:

if insig=TRUE, lab=FALSE
like image 321
Isabelle Bos Avatar asked Aug 23 '26 02:08

Isabelle Bos


1 Answers

I created a modified version of ggcorrplot called myggcorrplot with the new lab.notsig option (the label for not significant correlations).
Download the file here and save it in your working directory as myggcorrplot.r.
Then, run the following code:

library(ggcorrplot)  
library(mvtnorm)
# A toy dataset
set.seed(1)
n <- 100
p <- 7
A <- matrix(runif(p^2)*2-1, ncol=p) 
Sigma <- cov2cor(t(A) %*% A)
corCN <- data.frame(rmvnorm(n, mean=rep(0,p), sigma=Sigma))
colnames(corCN) <- c("Aß 1-38","Aß 1-40", "Aß 1-42", "Aß 42/40", "YKL-40", "Ng", "NFL")

corrCN <- cor(corCN, method=c("spearman"), use="complete.obs")
p.matCN <- cor_pmat(corCN, method=c("spearman"), use="complete.obs")

# Load the myggcorrplot function
source("myggcorrplot.r")
# Set in the lab.notsig option the label for not significant correlations
CNcorrplot <- myggcorrplot(corrCN, type="lower", lab=TRUE, 
              ggtheme = ggplot2::theme_classic,
              p.mat=p.matCN, insig ="blank", lab.notsig="NS")

CNcorrplot2 <- CNcorrplot + ggtitle("CN") + 
                   theme(plot.title = element_text(hjust = 0.5)) 
CNcorrplot2

enter image description here

like image 165
Marco Sandri Avatar answered Aug 24 '26 17:08

Marco Sandri