rggcorrplot

ggcorrplot2 shows different significance asterisks


does anybody have an idea why ggcorrplot2 shows different significance asterisks than ggcorrplot? Very confusing to me.

enter image description here

enter image description here

https://github.com/caijun/ggcorrplot2

data(mtcars)
ct <- corr.test(mtcars)
corr <- ct$r
p.mat <- ct$p
ggcorrplot(corr, type= "lower", p.mat = p.mat, 
                 insig = "label_sig", sig.lvl = c(0.05, 0.01, 0.001),show.diag=F)
ggcorrplot.mixed(corr, upper = "number", lower = "circle", p.mat = p.mat, 
                 insig = "label_sig", sig.lvl = c(0.05, 0.01, 0.001))

Update: Ok I think I figured it out finally. Its because corr.test() writes a unsymmetric matrix of p.values. "Entries above the diagonal are adjusted for multiple tests." I fixed this with p.mat[lower.tri(p.mat)] <- t(p.mat)[lower.tri(p.mat)]. Furthermore if you want to use the adjusted p.Values it is important to mirror the triangle above the diagonal of the p.Value matrix. If you need the unadjusted p.Values it is the lower triangle that needs to be mirrored (code needs to be changed accordingly).

data(mtcars)
cor.matrix <- corr.test(mtcars,method = "spearman", adjust = "BH", alpha = 0.05, ci = F)
corr <- cor.matrix[["r"]]
p.mat <- cor.matrix[["p"]]
p.mat[lower.tri(p.mat)] <- t(p.mat)[lower.tri(p.mat)] #to get only the adjusted p.Values symmetrically over the plot

p.mat[lower.tri(p.mat, diag = T)] <- 1 #to set the lower triangle to 1
corrplot.mixed(corr, order= "original",mar=c(0,0,2,0), tl.col = 'black', p.mat = p.mat, insig = "label_sig", sig.level = c(.001, .01, .05), pch.cex=1.5, tl.cex = .8, number.font=2, number.cex=0.8)

Final Corrplot


Solution

  • data(mtcars)
    cor.matrix <- corr.test(mtcars,method = "spearman", adjust = "BH", alpha = 0.05, ci = F)
    corr <- cor.matrix[["r"]]
    p.mat <- cor.matrix[["p"]]
    p.mat[lower.tri(p.mat)] <- t(p.mat)[lower.tri(p.mat)] #to get only the adjusted p.Values symmetrically over the plot
    
    p.mat[lower.tri(p.mat, diag = T)] <- 1 #to set the lower triangle to 1 (this way the asterisks wont be displayed on this part of the graph)
    corrplot.mixed(corr, order= "original",mar=c(0,0,2,0), tl.col = 'black', p.mat = p.mat, insig = "label_sig", sig.level = c(.001, .01, .05), pch.cex=1.5, tl.cex = .8, number.font=2, number.cex=0.8)