Treemap

Authors

[Editor] Hu Zheng;

[Contributors]

Modified

2026-01-27

Note

Hiplot website

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

Tree map is a kind of tree structure diagram that graphical form to represent hierarchy structure.

Setup

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

  • Programming language: R

  • Dependent packages: data.table; jsonlite; treemap

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

# Load packages
library(data.table)
library(jsonlite)
library(treemap)
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-27
 pandoc   3.1.3 @ /usr/bin/ (via rmarkdown)
 quarto   1.8.27 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package    * version date (UTC) lib source
 data.table * 1.18.0  2025-12-24 [1] RSPM
 jsonlite   * 2.0.0   2025-03-27 [1] RSPM
 treemap    * 2.4-4   2023-05-25 [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

The loaded data are different groups and their data.

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

# View data
head(data)
   group value
1 Group1    13
2 Group2    34
3 Group3    21
4 Group4    43

Visualization

# Treemap
treemap(data, index = colnames(data)[1], vSize = colnames(data)[2],
        vColor = colnames(data)[1], type = "index", title = "", 
        algorithm = "pivotSize", sortID = colnames(data)[1], border.lwds = 1,
        fontcolor.labels = "#000000", inflate.labels = F, overlap.labels = 0.5,
        fontfamily.title = "Arial", fontfamily.legend = "Arial",
        fontfamily.labels = "Arial", 
        palette = c("#E64B35FF","#4DBBD5FF","#00A087FF","#3C5488FF","#F39B7FFF"), 
        aspRatio = 6 / 6)
FigureΒ 1: Treemap

Different colors represent different groups and different areas represent data and proportion.