Adding significance level
Basically, the significance level is denoted by alpha. We compare the significance level to p-values to check whether the correlation between variables is significant or not. If p-value is less than equal to alpha, then the correlation is significant else, non-significant.
We will visualize our correlation matrix by adding significance level not taking any significant coefficient. We will do this using the ggcorrplot function and taking arguments as our correlation matrix, hc.order, type, and our correlation matrix with p-values.
Syntax :
ggcorrplot(correlation_matrix, hc.order=TRUE, type=”lower”, p.mat=corrp.mat)
Parameters :
- correlation_matrix : Our correlation matrix to visualize.
- hc.order : If its value is true, then the correlation matrix will be ordered.
- type : It is the arrangement of the character to display.
- p.mat : Correlation matrix with p-values.
Example: Adding coefficient significance level
R
library (ggplot2) library (ggcorrplot) # Reading the data data (USArrests) # Computing correlation matrix correlation_matrix <- round ( cor (USArrests),1) # Computing correlation matrix with p-values corrp.mat <- cor_pmat (USArrests) # Adding correlation significance level ggcorrplot (correlation_matrix, hc.order = TRUE , type = "lower" , p.mat = corrp.mat) |
Output :
Visualization of a correlation matrix using ggplot2 in R
In this article, we will discuss how to visualize a correlation matrix using ggplot2 package in R programming language.
In order to do this, we will install a package called ggcorrplot package. With the help of this package, we can easily visualize a correlation matrix. We can also compute a matrix of correlation p-values by using a function that is present in this package. The corr_pmat() is used for computing the correlation matrix of p-values and the ggcorrplot() is used for displaying the correlation matrix using ggplot.
Syntax :
corr_pmat(x,..)
Where x is the dataframe or the matrix
Syntax:
ggcorrplot(corr, method = c(“circle”, “square”), type = c(“full”, “lower”, “upper”), title = “”, ggtheme=ggplot2::theme_minimal, show.legend = TRUE, legend.title = “corr”, show.diag = FALSE, colors = c(“blue”, “white”, “red”), outline.color = “gray”, hc.order = FALSE, hc.method = “complete”, lab = FALSE, lab_col =”black”, p.mat = NULL,.. )
Contact Us