Matrix Bubble

Authors

[Editor] Hu Zheng;

[Contributors]

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: ggalluvial; ggplot2

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

# Load packages
library(ggalluvial)
library(ggplot2)

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 <- read.delim("files/Hiplot/118-matrix-bubble-data.txt", header = T)

# 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