Plotting the upper triangle of the correlation heatmap
Let’s check out how to plot the upper triangle of the correlation heatmap and visualize it. This can be done by replacing the lower triangle values of the correlation matrix as NA and then this matrix is reduced by melting process and plotted.
R
# get the corr matrix corr_mat <- round ( cor (data),2) # replace NA with lower triangle matrix corr_mat[ lower.tri (corr_mat)] <- NA # reduce the corr matrix melted_corr_mat <- melt (corr_mat) # plotting the corr heatmap library (ggplot2) ggplot (data = melted_corr_mat, aes (x=Var1, y=Var2, fill=value)) + geom_tile () |
Output:
How to Create Correlation Heatmap in R
In this article let’s check out how to plot a Correlation Heatmap in R Programming Language.
Analyzing data usually involves a detailed analysis of each feature and how it’s correlated with each other. It’s essential to find the strength of the relationship between each feature or in other words how two variables move in association to each other. If the variables grow together in the same direction it’s a positive correlation otherwise a negative correlation. This correlation can be visualized via various graphs such as scatter plots etc.