ggmosaic was designed to create visualizations of categorical data and is capable of producing bar charts, stacked bar charts, mosaic plots, and double decker plots.
library(ggmosaic)
#> Loading required package: ggplot2
data(fly)
head(fly) %>% kable()
id | flight_freq | do_you_recline | height | has_child_under_18 | three_seats_two_arms | two_seats_one_arm | window_shade | rude_to_move_to_unsold_seat | rude_to_talk_to_neighbor | six_hr_flight_leave_seat | reclining_obligation_to_behind | rude_to_recline | eliminate_reclining | rude_to_switch_seats_friends | rude_to_switch_seats_family | rude_to_wake_neighbor_bathroom | rude_to_wake_neighbor_walk | rude_to_bring_baby | rude_to_bring_unruly_child | use_electronics_takeoff | smoked_inflight | gender | age | household_income | education | region |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3436139758 | once a year or less | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
3434278696 | once a year or less | about half the time | 6’3" | yes | shared | shared | everyone | no | no | twice | yes | somewhat | no | no | no | no | no | no | no | no | no | male | 30-44 | NA | graduate degree | pacific |
3434275578 | once a year or less | usually | 5’8" | no | first_to_use_it | shared | window | no | no | three_times | yes | no | no | no | no | no | somewhat | somewhat | yes | no | no | male | 30-44 | $100,000 - $149,999 | bachelor degree | pacific |
3434268208 | once a year or less | always | 5’11" | no | shared | shared | everyone | no | no | three_times | no | no | no | somewhat | no | no | somewhat | somewhat | yes | no | no | male | 30-44 | $0 - $24,999 | bachelor degree | pacific |
3434250245 | once a month or less | about half the time | 5’7" | no | middle_seat | aisle_seat | everyone | no | no | twice | no | no | no | no | no | somewhat | somewhat | somewhat | yes | yes | no | male | 30-44 | $50,000 - $99,999 | bachelor degree | pacific |
3434245875 | once a year or less | usually | 5’9" | yes | first_to_use_it | first_to_use_it | window | somewhat | no | once | yes | no | no | somewhat | no | somewhat | yes | yes | yes | no | no | male | 30-44 | $25,000 - $49,999 | graduate degree | midwest |
ggplot(data = fly) +
geom_mosaic(aes(x = product(rude_to_recline), fill=do_you_recline)) +
theme_mosaic()