Basic waffle chart in R



This post explains how to build a very basic waffle chart with R. It uses the waffle package, provides reproducible code and explain how input data must be formatted.

For a more advanced usage of waffle charts, check out this post

Waffle section Data to Viz

Libraries and dataset


The waffle package provides a waffle() function that allows to build waffle charts.

Install the package with install.packages("waffle").

The input dataset is simple: we just have 3 groups, and each one has a value.

# library
#install.packages("waffle")
library(waffle)
 
# Create data
group <- c("group-1","group-2","group-3")
value <- c(13,5,22)
data <- data.frame(group,value)

Most basic waffle


Thanks to the waffle function, we can easily build a waffle chart.

waffle(data)

Change output


The default output will have 10 rows, but you can change this with the rows argument:

waffle(data, rows = 5)

Colors


You can change the color of the waffle chart with the colors argument. Here is an example with 3 colors:

waffle(data, rows = 5, colors = c("#fb5607", "#ff006e", "#8338ec"))

Legend position


You can change the position of the legend with the legend_pos argument. Here is an example with the legend on the bottom:

waffle(data, rows = 5, colors = c("#fb5607", "#ff006e", "#8338ec"), legend_pos = "bottom")

Going further


You might be interested in creating waffle charts with ggplot and waffle charts with subgroups.

Related chart types


Grouped and Stacked barplot
Treemap
Doughnut
Pie chart
Dendrogram
Circular packing



❤️ 10 best R tricks ❤️

👋 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! 🔥