• 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
• pro@slogix.in
• +91- 81240 01111

### How to Visualize Correlation Matrix using Correlogram in R?

###### Description

To visualize the correlation matrix using correlogram using R programming.

#### Correlation:

•  A correlation is a single number that describes the degree of relationship between two variables.

#### Correlation Matrix:

•  A correlation matrix is a table showing correlation coefficients between sets of variables
•  R Function : cor(Data Frame)

#### Correlation Matrix with significance levels:

•  R Package : Hmisc
•  R Function : rcorr(Correlation Matrix)

#### Methods for Visualizing Correlation Matrix:

•  corrplot()function to plotCorrelogram
•  symnum()function
•  Scatter plot

•  Circle
•  Pie
•  Color
•  Number

#### Types of correlogram layout:

•  full(default) : display full correlationmatrix
•  upper: display upper triangular of thecorrelation matrix
•  lower: display lower triangular of thecorrelation matrix
###### Sapmle Code

#Visualize Correlation Matrix using Correlogram

#Get and Set Working Directory
print(getwd())
setwd(“/home/soft13”)
getwd()

#install.packages(“xlsx”)
library(“xlsx”)
View(my_data)

#Compute Correlation Matrix
input<-cor(my_data)
print(input)

#Visualization
library(“corrplot”)

#Using Circle method

corrplot(input,method = “circle”, type = “upper”)

#Adding Colour and Background Colour To the Circle method
corrplot(input,method = “circle”, type = “upper”, col= c(“black”,”white”),bg=”lightblue”)

#Using Pie method
corrplot(input, method = “pie”)

#Using Color Method
corrplot(input, method = “color”, type = “lower”)

#Using Number method
corrplot(input, method = “number”, type = “full”, order=”hclust”)

#Adding text label Colour and text label string rotation
corrplot(input, method = “pie”,tl.col=”Black”,tl.srt = 20)

#Adding Significance level to the Correlogram
library(“Hmisc”)
input1<-rcorr(as.matrix(input))
print(input1)
pval<-as.matrix(input1\$P)
print(pval)
corrplot(input,method=”circle”, p.mat= pval,sig.level=0.05)

#Leave blank on no significant coefficient
corrplot(input, method=”circle”,p.mat = pval,sig.level=0.05,insig=”blank”)