using ggplot

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
mtcars_cormat<-cor(mtcars)%>%as.data.frame()%>%rownames_to_column()%>%pivot_longer(-rowname)
mtcars_cormat
## # A tibble: 121 × 3
##    rowname name   value
##    <chr>   <chr>  <dbl>
##  1 mpg     mpg    1    
##  2 mpg     cyl   -0.852
##  3 mpg     disp  -0.848
##  4 mpg     hp    -0.776
##  5 mpg     drat   0.681
##  6 mpg     wt    -0.868
##  7 mpg     qsec   0.419
##  8 mpg     vs     0.664
##  9 mpg     am     0.600
## 10 mpg     gear   0.480
## # ℹ 111 more rows
mtcars_cormat%>%ggplot(aes(x=rowname,y=name,fill=value))+geom_tile()+geom_text(aes(label=round(value,2)),color="white")+scale_fill_gradient2(low = "red",high = "darkgreen",mid="white",midpoint = 0,limit=c(-1,1),name="pearson/ncorrelation")

library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.3.3
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
chart.Correlation(iris[1:4],histogram=TRUE)
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

library(corrplot)
## corrplot 0.92 loaded
head(mtcars)
##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
corrplot(cor(mtcars),addCoef.col = "white",number.cex = 0.8,number.digits = 1,diag = FALSE,bg="grey",outline = "black",addgrid.col = "white",mar = c(1,1,1,1))

corrplot(cor(mtcars),method = "color",type="lower")

corrplot(cor(mtcars),method = "color",type="lower",cl.length = 11,cl.pos = "b",tl.col = "black",addCoef.col = "grey",title = "few changes",mar = c(1,1,1,1))

corrplot(cor(mtcars),order = "AOE",type = "upper",tl.pos = "d",method="number")

corrplot(cor(mtcars),order = "AOE",type = "lower",tl.pos = "d",method="pie")

corrplot.mixed(cor(mtcars),order="AOE",lower = "pie",upper = "number",tl.pos = c("d"))

library(GGally)
## Warning: package 'GGally' was built under R version 4.3.3
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
GGally::ggpairs(iris,columns = 1:4)

library(ggplot2)
GGally::ggpairs(iris,columns = 1:4,ggplot2::aes(colour=Species))

GGally::ggcorr(mtcars,method = c(method="everything","pearson"),label=TRUE,label_alpha = TRUE)

GGally::ggcorr(mtcars,name = expression(rho),geom = "circle",max_size = 10,min_size = 2,size=3,hjust=0.75,nbreaks = 6,angle=45,palette = "Puor")
## Warning in pal_name(palette, type): Unknown palette Puor

library(corrgram)
## Warning: package 'corrgram' was built under R version 4.3.3
## 
## Attaching package: 'corrgram'
## The following object is masked from 'package:GGally':
## 
##     baseball
corrgram::corrgram(mtcars)

library(corrgram)
corrgram::corrgram(mtcars,order = TRUE,lower.panel = panel.shade,upper.panel = panel.pie,text.panel = panel.txt,cor.method = "pearson",main="corrgram(mtcars,order=TRUE)'")

corrgram::corrgram(mtcars,order = TRUE,lower.panel = panel.ellipse,upper.panel = panel.pts,text.panel = panel.txt,cor.method = "pearson",   diag.panel=panel.minmax,main="corrgram(mtcars,diag.panel=panel.minmax)'")

corrgram::corrgram(mtcars,order=NULL,lower.panel = panel.shade,upper.panel = NULL,text.panel = panel.txt)

corrgram(iris[1:4],lower.panel =panel.pts,upper.panel =panel.conf,diag.panel = panel.density,main="corrgram(iris[1:4],panel.pts/.density/.conf)")
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

corrgram(mtcars,order=TRUE,main="corrgram(mtcars)-panel.bar",lower.panel = corrgram::panel.ellipse,upper.panel = panel.bar,diag.panel = panel.minmax,col.regions = colorRampPalette(c("darkgoldenrod4","burlywood1","darkkhaki","darkgreen")))

## pairs

library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
pairs.panels(iris[1:4])

psych::corPlot(iris[1:4],cex=0.9)

psych::corPlot(iris[1:4],cex=0.9)

gr<-colorRampPalette(c("white","lightblue","lightgreen"))
corPlot(iris[1:4],cex = 0.9,numbers = TRUE,n=5,zlim = c(-0.5,1),stars = TRUE,diag = F,gr=gr,main="psych::corrPlot(iris[1:4])")