Piestats Group

Authors

[Editor] Hu Zheng;

[Contributors]

Modified

2026-01-17

Note

Hiplot website

This page is the tutorial for source code version of the Hiplot Piestats Group 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/ggpiestats-group?lang=en

Setup

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

  • Programming language: R

  • Dependent packages: data.table; jsonlite; ggstatsplot; ggplot2; cowplot

# Install packages
if (!requireNamespace("data.table", quietly = TRUE)) {
  install.packages("data.table")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
  install.packages("jsonlite")
}
if (!requireNamespace("ggstatsplot", quietly = TRUE)) {
  install.packages("ggstatsplot")
}
if (!requireNamespace("ggplot2", quietly = TRUE)) {
  install.packages("ggplot2")
}
if (!requireNamespace("cowplot", quietly = TRUE)) {
  install.packages("cowplot")
}

# Load packages
library(data.table)
library(jsonlite)
library(ggstatsplot)
library(ggplot2)
library(cowplot)
sessioninfo::session_info("attached")
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.2 (2025-10-31)
 os       Ubuntu 24.04.3 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       UTC
 date     2026-01-17
 pandoc   3.1.3 @ /usr/bin/ (via rmarkdown)
 quarto   1.8.27 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 cowplot     * 1.2.0   2025-07-07 [1] RSPM
 data.table  * 1.18.0  2025-12-24 [1] RSPM
 ggplot2     * 4.0.1   2025-11-14 [1] RSPM
 ggstatsplot * 0.13.4  2025-12-09 [1] RSPM
 jsonlite    * 2.0.0   2025-03-27 [1] RSPM

 [1] /home/runner/work/_temp/Library
 [2] /opt/R/4.5.2/lib/R/site-library
 [3] /opt/R/4.5.2/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/ggpiestats-group/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)

# Convert data structure
axis <- c("genre", "mpaa")
data[, axis[1]] <- factor(data[, axis[1]], levels = unique(data[, axis[1]]))
data[, axis[2]] <- factor(data[, axis[2]], levels = unique(data[, axis[2]]))

# View data
head(data)
                                               title year length budget rating
1                          Shawshank Redemption, The 1994    142     25    9.1
2     Lord of the Rings: The Return of the King, The 2003    251     94    9.0
3 Lord of the Rings: The Fellowship of the Ring, The 2001    208     93    8.8
4             Lord of the Rings: The Two Towers, The 2002    223     94    8.8
5                                       Pulp Fiction 1994    168      8    8.8
6                                   Schindler's List 1993    195     25    8.8
   votes  mpaa  genre
1 149494     R  Drama
2 103631 PG-13 Action
3 157608 PG-13 Action
4 114797 PG-13 Action
5 132745     R  Drama
6  97667     R  Drama

Visualization

# Piestats Group
g <- unique(data[,axis[2]])
plist <- list()
for (i in 1:length(g)) {
  fil <- data[,axis[2]] == g[i]
  plist[[i]] <- 
    ggpiestats(
      data = data[fil,], x = genre, 
      title= paste('', axis[2], g[i], sep = ':'),
      plotgrid.args = list(ncol = 3),
      label.repel = TRUE,
      k = 2
    ) +
    scale_fill_manual(values = c("#3B4992FF","#EE0000FF","#008B45FF","#631879FF",
                                 "#008280FF","#BB0021FF","#5F559BFF","#A20056FF",
                                 "#808180FF"))
}

plot_grid(plotlist = plist, ncol = 3)
FigureΒ 1: Piestats Group