Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to Visualize Correlation Matrix using Correlogram in R?

Description

To visualize the correlation matrix using correlogram using R programming.

Process

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

Methods for Visualizing Correlation Matrix using Correlogram:

  •  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()

#Read file from Excel
#install.packages(“xlsx”)
library(“xlsx”)
my_data<-read.xlsx(“mtcars.xlsx”,sheetIndex=1)[,c(“mpg”,”cyl”,”disp”,”hp”,”drat”,”wt”,”qsec”)]
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”)

Screenshots
Visualize Correlation Matrix using Correlogram in R
Visualize Correlation Matrix using Correlogram
Get and Set Working Directory
Read file from Excel
Using Color Method
Correlation Matrix
correlation matrix is a table showing correlation coefficients between  sets of variables
Types of correlogram layout
Adding Significance level to the Correlogram