Treemap

Authors

[Editor] Hu Zheng;

[Contributors]

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: treemap

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

# Load packages
library(treemap)

Data Preparation

The loaded data are different groups and their data.

# Load data
data <- read.delim("files/Hiplot/173-treemap-data.txt", header = T)

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

Visualization

# Treemap
p <- 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)

p
$tm
   group vSize vColor stdErr vColorValue level        x0        y0         w
1 Group1    13      1     13          NA     1 0.0000000 0.8088235 0.6126126
2 Group2    34      1     34          NA     1 0.0000000 0.3088235 0.6126126
3 Group3    21      1     21          NA     1 0.0000000 0.0000000 0.6126126
4 Group4    43      1     43          NA     1 0.6126126 0.0000000 0.3873874
          h   color
1 0.1911765 #E64B35
2 0.5000000 #4DBBD5
3 0.3088235 #00A087
4 1.0000000 #3C5488

$type
[1] "index"

$vSize
[1] "value"

$vColor
[1] NA

$stdErr
[1] "value"

$algorithm
[1] "pivotSize"

$vpCoorX
[1] 0.2664042 0.7335958

$vpCoorY
[1] 0.0328084 0.9671916

$aspRatio
[1] 1

$range
[1] NA

$mapping
[1] NA NA NA

$draw
[1] TRUE
FigureΒ 1: Treemap

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