Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#Waffle chart
#1. Install all packages
install.packages("waffle")
library(waffle)
#2. Basic waffle
d <- c(50, 30, 20, 10)
waffle(d, rows = 10)
#3. Change size
d <- c(50, 30, 20, 10)
waffle(d, rows = 5, size = 0.5) +
theme_tufte()
#4. Add more data
d <- c(50, 30, 20, 10, 20, 30, 40)
waffle(d, rows = 10, size = 0.5)
#5. Change the position of the legend
d <- c(50, 30, 20, 10, 20, 30, 40)
waffle(d/2 , rows = 5, size = 0.1, legend_pos = "bottom")
#6. Real example
pain.adult.1997 <- c(`YOY (406)` = 406, `Adult (24)` = 24)
waffle(
pain.adult.1997 / 2, rows = 7, size = 0.5,
colors = c("steelblue", "grey"),
title = "Paine Run Brook Trout Abundance (1997)",
) -> A
pine.adult.1997 <- c(`YOY (221)` = 221, `Adult (143)` = 143)
waffle(
pine.adult.1997 / 2, rows = 7, size = 0.5,
colors = c("steelblue", "grey"),
title = "Piney River Brook Trout Abundance (1997)",
xlab = "1 square = 2 fish", pad = 8
) -> B
stan.adult.1997 <- c(`YOY (270)` = 270, `Adult (197)` = 197)
waffle(
stan.adult.1997 / 2, rows = 7, size = 0.5,
colors = c("steelblue", "grey"),
title = "Staunton River Trout Abundance (1997)",
xlab = "1 square = 2 fish"
) -> C
iron(A, B, C)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.