corrplot shows insignificant correlation coefficients even when insig = “blank” is set

后端 未结 2 821
梦毁少年i
梦毁少年i 2020-12-10 08:25

I like to use correlation plot using corrplot function with correlation coefficients printed in the cells (using addCoef.col and addCoefasPer

相关标签:
2条回答
  • 2020-12-10 09:01

    If you're not too picky, you could also leave the background set to white and make your addCoef.col = "white" instead of "grey" as you have it originally. That would eliminate the need for the ordering and ifelse statements.

    0 讨论(0)
  • You have to do a little work for this. You need to define a vector of colours manually for the p-values, that is passed to addCoef.col

    If you were ordering alphabetically, it is straight forward

    mycol <- ifelse(c(cor1[[1]] < 0.05), "black", "white")
    
    corrplot(cor(test), p.mat = cor1[[1]] , insig = "blank", method = "color", 
             addCoef.col=mycol ,
             order = "original", tl.cex = 1/par("cex"), 
             cl.cex = 1/par("cex"), addCoefasPercent = TRUE)
    

    But as you want to order by the eigenvalues you need to calculate the ordering outside of the corrplot function

    ord <-   corrMatOrder(cor(test), order="AOE")
    M <- cor(test)[ord, ord]
    
    pval <- psych::corr.test(data.frame(test), adjust="none")$p[ord, ord]
    mycol <- ifelse(c(pval < 0.05), "black", "white")
    
    
    corrplot(M, p.mat = pval , insig = "blank", method = "color", addCoef.col=mycol ,
             order = "original", tl.cex = 1/par("cex"), 
             cl.cex = 1/par("cex"), addCoefasPercent = TRUE)
    

    enter image description here


    EDIT re @Masi's comments

    To update the limits on the colourbar set the limits with cl.lim

     corrplot(cor(test), p.mat = cor1[[1]] , insig = "blank", method = "color", 
           addCoef.col=mycol , addCoefasPercent=TRUE, 
           order = "original", cl.lim = c(-100, 100))
    
    0 讨论(0)
提交回复
热议问题