Waffle Plot

Authors

[Editor] Hu Zheng;

[Contributors]

Modified

2026-04-20

πŸ€– AI Skill β€” Download the Bizard unified skill for your AI assistant ⬇️ Download Skill ZIP
Note

Hiplot website

This page is the tutorial for source code version of the Hiplot Waffle Plot plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:

https://hiplot.cn/basic/waffle?lang=en

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)

  • Programming language: R

  • Dependent packages: data.table; jsonlite; waffle

# Install packages
if (!requireNamespace("data.table", quietly = TRUE)) {
  install.packages("data.table")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
  install.packages("jsonlite")
}
if (!requireNamespace("waffle", quietly = TRUE)) {
  remotes::install_github("hrbrmstr/waffle")
}

# Load packages
library(data.table)
library(jsonlite)
library(waffle)
sessioninfo::session_info("attached")
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.3 (2026-03-11)
 os       Ubuntu 24.04.4 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       UTC
 date     2026-04-21
 pandoc   3.1.3 @ /usr/bin/ (via rmarkdown)
 quarto   1.9.37 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package    * version    date (UTC) lib source
 data.table * 1.18.2.1   2026-01-27 [1] RSPM
 ggplot2    * 4.0.2.9000 2026-04-14 [1] Github (tidyverse/ggplot2@7d79c95)
 jsonlite   * 2.0.0      2025-03-27 [1] RSPM
 waffle     * 1.0.2      2026-04-03 [1] Github (hrbrmstr/waffle@767875b)

 [1] /home/runner/work/_temp/Library
 [2] /opt/R/4.5.3/lib/R/site-library
 [3] /opt/R/4.5.3/lib/R/library
 * ── Packages attached to the search path.

──────────────────────────────────────────────────────────────────────────────

Data Preparation

# Load data
data <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/waffle/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)

# convert data structure
parts <- data[,2]

# View data
head(data)
                      label value
1 Un-breached US Population   230
2                   Premera    11
3                    Anthem    79

Visualization

# Waffle Plot
p <- waffle(parts, rows = 8, size = 1, legend_pos = "right") +
  ggtitle("Waffle Plot") +
  scale_fill_manual(values = c("#e04d39","#5bbad6","#1e9f86")) +
  theme(text = element_text(family = "Arial"),
        plot.title = element_text(size = 12,hjust = 0.5),
        axis.title = element_text(size = 12),
        axis.text = element_text(size = 10),
        axis.text.x = element_text(angle = 0, hjust = 0.5,vjust = 1),
        legend.position = "right",
        legend.direction = "vertical",
        legend.title = element_text(size = 10),
        legend.text = element_text(size = 10))

p
FigureΒ 1: Waffle Plot