Waffle charts for visualizing proportions

Application exercise

February 8, 2024


Go to the course GitHub organization and locate the repo titled ae-04-YOUR_GITHUB_USERNAME to get started.

This AE is due February 9 at 11:59pm.


# fix seed value for reproducibility


Waffle charts

ggwaffle provides a ggplot2 implementation of waffle plots. The typical workflow consists of preparing the data with waffle_iron() and then plotting it with ggplot2 and geom_waffle().

Basic waffle chart

Demonstration: Prepare the penguins data frame to visualize the number of penguins by species.

# add code here

Demonstration: Use the prepared data to draw a basic color-coded waffle chart

# add code here

Improve the waffle chart

Your turn: Adjust the waffle chart to use a fixed aspect ratio so the symbols are squares.

# add code here

Demonstration: ggwaffle will draw all observations on the chart. For larger datasets, this is problematic. Instead, we might want to visualize the proportion of observations in each category. In order to produce the desired data structure, we need to use slice_sample() to sample the data and weight_by to sample the data proportionally to the number of observations in each category.

# add code here

Your turn: Adjust the waffle chart to use a better color palette and move the legend to the top.

# add code here

(Stretch) demonstration: Use the emojifont package to visualize each waffle “square” using a penguin emoji.

# add code here