Here we will have to install and load ggplot2 in order to use the
geom_waffle() function.
install.packages("ggplot2")
library(ggplot2)
We will be using the previously summarised data in this example as
well.
ggplot(df1, aes(fill = Commodity, values = Count)) +
geom_waffle(n_rows = 5, size = 0.5, colour = "white", na.rm = T)

We can change the colours of the plot and the legend position here
as well, with the help of “scale_fill_manual()”. To make this plot
designed by using ggplot2 look more like the waffle one, we can use
“coord_equal()” to make sure that the units are equally scaled on both
the axes (i.e. to acquire square tiles) and “theme_void()” to remove the
gridlines and labels.
ggplot(df1, aes(fill = Commodity, values = Count)) +
geom_waffle(n_rows = 5, size = 2, colour = "white", na.rm = T) +
scale_fill_manual(name = NULL,
values = c("#210578", "#b65ea8", "#dfb9c2", "#5a1d8d", "#ca89ac", "#923aa1"),
labels = c(df1$Commodity)) +
coord_equal() +
theme_void() +
theme(legend.position = "bottom")
