library(tidyverse)
library(palmerpenguins)
library(waffle)
library(viridis)
# fix seed value for reproducibility
set.seed(123)
theme_set(theme_void())
AE 05: Waffle charts for visualizing proportions
Waffle charts
{waffle} provides a {ggplot2} implementation of waffle plots. The typical workflow consists of preparing the data by tabulating in advance 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. Rotate the chart so the squares are stacked vertically.
# add code here
Demonstration: {waffle} 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. Use geom_waffle()
to represent the data as proportions instead.
# 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