Q6 We use correlation to examine the strength of linear relationships between variables.
Two variables that are strongly correlated with each other will have correlations close to
either 1 (strongly positive) or -1 (strongly negative). Correlation values are only calculated
(in any way that makes sense) for numeric variables.
Use the line of code below to create a correlation matrix for the numeric variables in this
dataset. Note that ggcorr is from the GGally package.
{r}
ggcorr(mpg, label = TRUE, label_round = 3)
Which variable is most strongly correlated with \"hwy\"? Which variable is the second most
strongly correlated with \"hwy\"?
Q7 You can develop a plot that shows a plot for each combination of variables as well as
the correlations using the ggpairs function. Note that ggpairs is from the GGally package.
Use the code below to develop a ggpairs plot for this dataset. Note that I have listed the
columns in the dataset that I want to see in the plot rather than including all columns. The
ggpairs plot can easily become too cluttered if you include too many variables. Columns
must be specified by column number. To avoid clutter, I have created two separate plots.
Both plots include the variable of interest (hwy) that is in column nine. The plots are still a
bit messy. The only required output for this question is the two plots.
{r}
ggpairs(mpg, columns = c(9, 3, 5:7))
{r}
ggpairs(mpg, columns = c(8:11))