O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Visualizing a correlation matrix with ggplot2

We will use the reshape package to melt the correlation matrix and then use the geom_tile() function from the ggplot2 package to visualize the correlation matrix. In the case of large data, the geom_raster() function can be used in place of the geom_tile function.

> library(reshape2)> melted_cormat <- melt(mtcars_cor)> head(melted_cormat)> ggplot(data = melted_cormat, aes(x=Var1, y=Var2, fill=value)) + geom_tile()

This default plot is not visually appealing; hence, in the next recipe, we will show you the advanced feature of visualizing a correlation matrix through a heatmap.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required