In this exercise you will learn to visualize the pairwise relationships between a set of quantitative variables. To this end, you will make your own note of 8.1 Correlation plots from Data Visualization with R.
# import data
data(SaratogaHouses, package="mosaicData")
# select numeric variables
df <- dplyr::select_if(SaratogaHouses, is.numeric)
# calulate the correlations
r <- cor(df, use="complete.obs")
round(r,2)
library(ggplot2)
library(ggcorrplot)
# visualize the correlations
ggcorrplot(r,
hc.order = TRUE,
type = "lower",
lab = TRUE)
Rooms, bathrooms and landvalue
Living area has the strongest correlation with home price.
Age is the only negative correlation with home price
age has the weaskest correlation with home price.
Living area and number of rooms
Hint: The CPS85 data set is from the mosaicData package. Explain wage instead of home price.
# import data
data(CPS85, package="mosaicData")
# select numeric variables
df <- dplyr::select_if(CPS85, is.numeric)
# calulate the correlations
r <- cor(df, use="complete.obs")
round(r,2)
library(ggplot2)
library(ggcorrplot)
# visualize the correlations
ggcorrplot(r,
hc.order = TRUE,
type = "lower",
lab = TRUE)
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.