8.15 Mosaic Plots

  • Mosaic charts can display the relationship between categorical variables using rectangles whose areas represent the proportion of cases for any given combination of levels.

  • He we look at the Titanic dataset and visualize the relationship between the three categorical variables in the code below.

# input data
library(readr)
titanic <- read_csv("data/titanic.csv")

# create a table
tbl <- xtabs(~Survived + Class + Sex, titanic)
ftable(tbl)
##                Sex Female Male
## Survived Class                
## No       1st            4  118
##          2nd           13  154
##          3rd          106  422
##          Crew           3  670
## Yes      1st          141   62
##          2nd           93   25
##          3rd           90   88
##          Crew          20  192