Creating a Correlation Plot

In this section, we'll make a correlation plot for all continuous variables in the gapminder dataset. Let's begin by implementing the following steps:

  1. Choose only continuous variables by using the following command:
dfs1 <- dfs[,colnames(dfs)[4:9]]
  1. Remove all NAs; otherwise, the correlation will not work, because it requires finite values:
dfs1 <- na.omit(dfs1)
  1. Get the correlation matrix, M, using the following command:
M <- cor(dfs1)
  1. Plot the correlation matrix using the following command:
corrplot(M,method="circle") 

The plot will look as follows:

  1. The preceding plot looks messy because of its long names. ...

Get Applied Data Visualization with R and ggplot2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.