Chord Plot

Authors

[Editor] Hu Zheng;

[Contributors]

Modified

2026-01-17

Note

Hiplot website

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

The complex interaction is visualized in the form of chord graph.

Setup

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

  • Programming language: R

  • Dependent packages: data.table; jsonlite; circlize; ggplotify

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

# Load packages
library(data.table)
library(jsonlite)
library(circlize)
library(ggplotify)
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
 circlize   * 0.4.17  2025-12-08 [1] RSPM
 data.table * 1.18.0  2025-12-24 [1] RSPM
 ggplotify  * 0.1.3   2025-09-20 [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

Data frame or matrix of interaction of genes with pathways or gene ontologys.

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

# convert data structure
row.names(data) <- data[, 1]
data <- data[, -1]
data <- as.matrix(data)

# View data
head(data)
   E1 E2 E3 E4 E5
S1  4 16 12 18 11
S2  7 11  2 15 10
S3  9  2 17 16 11
S4 14  9 12  3 17
S5  1  1  7  1 12
S6 10 18  9 13  9

Visualization

# Chord Plot
Palette <- c("#E64B35FF","#4DBBD5FF","#00A087FF","#3C5488FF","#F39B7FFF",
             "#8491B4FF","#91D1C2FF","#DC0000FF","#7E6148FF","#B09C85FF")
grid.col <- c(Palette, Palette, Palette[1:5])
p <- as.ggplot(function() {
  chordDiagram(
    data, grid.col = grid.col, grid.border = NULL, transparency = 0.5,
    row.col = NULL, column.col = NULL,  order = NULL,
    directional = 0, # 1, -1, 0, 2
    direction.type = "diffHeight", # diffHeight and arrows
    diffHeight = convert_height(2, "mm"), reduce = 1e-5, xmax = NULL, 
    self.link = 2, symmetric = FALSE, keep.diagonal = FALSE, 
    preAllocateTracks = NULL,
    annotationTrack = c("name", "grid", "axis"),
    annotationTrackHeight = convert_height(c(3, 3), "mm"),
    link.border = NA, link.lwd = par("lwd"), link.lty = par("lty"), 
    link.sort = FALSE, link.decreasing = TRUE, link.largest.ontop = FALSE,
    link.visible = T, link.rank = NULL, link.overlap = FALSE,
    scale = F, group = NULL, big.gap = 10, small.gap = 1
    )
  })

p
FigureΒ 1: Chord Plot