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.5 Mosaic plots from Data Visualization with R.
Mosaic charts can display the relationship between categorical variables using:
The Titanic data set came from https://osf.io/aupb4/.
## ── Attaching packages ───────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.2
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 0.8.3 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## Parsed with column specification:
## cols(
## Name = col_character(),
## PClass = col_character(),
## Age = col_double(),
## Sex = col_character(),
## Survived = col_double()
## )
In the graph below,
## Loading required package: grid
No, more passengers did not survive because the grouping for no survivors is bigger and has more height to the boxes than those who did survive.
The largest group that did not survive was the third class men because the box is the biggest and blue which means more men died than expected.
The largest group that did survive was the first class females. The box is long and blue which means more woman survived than expected.
The group that has more cases than expected given independence is men in the 3rd class who did not survive because the box is big and blue meaning more men died than expected.
The group that has less cases than expected given independence are females in the 1st class who did not survive. The box is the smallest pink box which means less women in the 1st class did not survive
Hint: The Arthritis data set is from the vcd package. Add an additional argument gp = shading_max in the mosaic function. This is because the residuals are too small to have color.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.