This post explains how to build a
waffle chart with R using the
geom_waffle()
function. It uses the
waffle
package, provides reproducible code and explain
how to customize the chart.
Install the package with
install.packages("waffle")
.
The input dataset is simple: we just have 3 groups, and each one has a value.
The waffle
package provides a
geom_waffle()
function that allows to build
waffle charts with ggplot2.
You can customize the colors of the waffle chart
using the scale_fill_manual()
function and the edge color
with the color
argument:
ggplot(data, aes(fill=group, values=value)) +
geom_waffle(color = "white") +
scale_fill_manual(values = c("#999999", "#E69F00", "#56B4E9")) +
theme_void()
You can change labels in legend to the waffle chart:
ggplot(data, aes(fill=group, values=value)) +
geom_waffle() +
scale_fill_manual(
values = c("#999999", "#E69F00", "#56B4E9"),
labels = c("First group", "Second group", "Third group")) +
theme_void()
You might be interested in how to create waffle chart without ggplot and how to create waffle charts with groups and subgroups.
👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥