Matrix Bubble

Authors

[Editor] Hu Zheng;

[Contributors]

Modified

2026-01-17

Note

Hiplot website

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

The color matrix bubble is used to visualize the expression matrix data of multiple genes (rows) in various cells (columns).

Setup

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

  • Programming language: R

  • Dependent packages: data.table; jsonlite; ggalluvial; ggplot2

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

# Load packages
library(data.table)
library(jsonlite)
library(ggalluvial)
library(ggplot2)
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
 data.table * 1.18.0  2025-12-24 [1] RSPM
 ggalluvial * 0.12.5  2023-02-22 [1] RSPM
 ggplot2    * 4.0.1   2025-11-14 [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 Structure:

  • <1st-col>: (String) cell sample name as X axis
  • <2nd-col>: (String) gene name as the Y axis
  • <3rd-col>: (Numeric) gene expression
  • <4rd-col>: (Numeric) groups
# Load data
data <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/matrix-bubble/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)

# Convert data structure
data[, 1] <- factor(data[, 1], levels = unique(data[, 1]))
data[, 2] <- factor(data[, 2], levels = unique(data[, 2]))

# View data
head(data)
      x     y value  group
1 cell1 gene1     1 groupC
2 cell1 gene2     5 groupC
3 cell1 gene3    10 groupC
4 cell1 gene4    15 groupC
5 cell1 gene5    20 groupC
6 cell1 gene6    25 groupC

Visualization

# Matrix Bubble
p <- ggplot(data = data, aes(x = x, y = y, size = value, color = y)) +
  geom_point(alpha = 1) +
  labs(title = "Matrix Bubble") +
  guides(color = FALSE) +
  theme(panel.background = element_blank(),
        panel.grid.major = element_line(colour = "gray"),
        strip.background = element_blank(),
        panel.border = element_rect(colour = "black", fill = NA),
        panel.spacing = unit(0, "lines"),
        plot.title = element_text(size = 12, hjust = 0.5),
        text = element_text(family = "Arial"),
        legend.title = element_text(size = 10),
        axis.text.x = element_text(angle=0, hjust=0.5, vjust=1)) +
  facet_grid(~group, scales = 'fixed', margins = F) +
  scale_color_manual(values = c(
    "#3B4992FF","#EE0000FF","#008B45FF","#631879FF","#008280FF","#BB0021FF",
    "#5F559BFF","#A20056FF","#808180FF","#1B1919FF"))

p
FigureΒ 1: Matrix Bubble