rm(list = ls())

workdir      = "G:/Dropbox/idx/topic/20200929T140515"
setwd(workdir)


library(corrplot)
## corrplot 0.84 loaded
library(psych)


CorPcorPlot <- function(xtitle,x){
  graphics.off()
  windows()
 
  x.cor  <- corr.test(x)
  x.pcor <- corr.p(partial.r(x),n=x.cor$n)
  x.lowup <- lowerUpper(lower=x.cor$r,upper=x.pcor$r,diff=FALSE)
  x.lowup_pvalue <- lowerUpper(lower=x.cor$p,upper=x.pcor$p,diff=FALSE)

corrplot::corrplot(x.lowup,
           method="ellipse",
       #    add = FALSE,
           diag=FALSE,
       #    title=xtitle,
           # label=TRUE,
           p.mat = x.lowup_pvalue, 
           #  sig.level = c(0.001,0.01,0.05),
        #   sig.level = 0.01,
           #  insig="label_sig",
           insig="blank",
         #  tl.cex = 1,
           addCoef.col = "black",
           #  addCoefasPercent = TRUE,
           outline=FALSE,
           pch.cex = 1.5,
           #cl.length = 21,
           #     pch=  "*"
  )
savePlot(filename = "1.png",type="png")
windows()

psych::corPlot(x.lowup,
          colors=TRUE,
          #   numbers=FALSE,
          pval=x.lowup_pvalue,
          cex=1,
          main=xtitle,
          diag = FALSE,
          stars=TRUE,
          show.legend = TRUE
          )
savePlot(filename = "2.png",type="png")
}
CorPcorPlot("mtcars",subset(mtcars,select=c(2,3,4,5,6)))

corrplot::corrplot psych::corPlot