reglScatterplotR

reglScatterplotR is an htmlwidgets interface to the JavaScript regl-scatterplot library, rendering millions of two-dimensional points in the browser via WebGL. Built for exploratory visualisation of single-cell, spatial transcriptomics and other high-dimensional biological data.

Panning, lassoing and legend-filtering an interactive UMAP

Python? A companion package, reglscatterpy, drives the same compiled widget from Python (AnnData / MuData / SpatialData) in Jupyter, VS Code and Colab — so plots look identical across the two languages.

Features

Installation

# From GitHub (development version)
remotes::install_github("george123ya/reglScatterplotR")

# Once accepted into Bioconductor
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("reglScatterplotR")

Quick start

library(reglScatterplotR)

# Plain data.frame
set.seed(1L)
df <- data.frame(
    x       = rnorm(20000),
    y       = rnorm(20000),
    cluster = sample(letters[1:6], 20000, replace = TRUE),
    score   = runif(20000)
)
reglScatterplot(df, x = "x", y = "y", colorBy = "cluster")
reglScatterplot(df, x = "x", y = "y", colorBy = "score",
                continuousPalette = "magma",
                vmin = "p1", vmax = "p99")

Try it with the bundled dataset

# Ships with the package - no download needed
data(reglScatterExample)
reglScatterplot(reglScatterExample,
                x = "UMAP_1", y = "UMAP_2", colorBy = "celltype")
reglScatterplot(reglScatterExample,
                x = "UMAP_1", y = "UMAP_2", colorBy = "CD3D",
                continuousPalette = "viridis", vmax = "p99")

SingleCellExperiment one-liner

library(SingleCellExperiment)
# sce already has reducedDim(sce, "UMAP") + colData(sce)$cluster
reglScatterplot(sce, x = "UMAP", colorBy = "cluster")

# Or colour by a gene
reglScatterplot(sce, x = "UMAP", colorBy = "MS4A1")

SpatialExperiment tissue map

library(SpatialExperiment)
reglScatterplot(spe, x = "spatial", colorBy = "celltype",
                autoFit = TRUE)

Seurat object

library(Seurat)
# seurat_obj already has an "umap" reduction + meta.data
reglScatterplot(seurat_obj, x = "umap", colorBy = "seurat_clusters")

# colorBy resolves meta.data columns OR features (via FetchData)
reglScatterplot(seurat_obj, x = "umap", colorBy = "MS4A1")

AnnData

# In-memory AnnData from anndataR or the anndata package
library(anndataR)
ad <- read_h5ad("pbmc.h5ad")
reglScatterplot(ad, x = "umap", colorBy = "leiden")  # obs column or a gene

# (AnnData read with zellkonverter::readH5AD() is an SCE - use x = "UMAP")

Gallery

Categorical colouring Continuous (gene) colouring
Categorical UMAP with frosted legend Gene-expression UMAP with colour bar
filterBy distribution sliders Synced plots (syncPlots)
Range-filter sliders with histograms Two embeddings with linked pan/zoom

Documentation

Topic Where
Tour with examples vignette("reglScatterplot")
Scaling to millions of points vignette("performance")
Wiki: extended recipes https://github.com/george123ya/reglScatterplotR/wiki
Issue tracker https://github.com/george123ya/reglScatterplotR/issues

Performance at a glance

Point count Status HTML size (typical)
≤ 500 k Flawless < 5 MB
500 k – 5 M Smooth 10 – 40 MB
5 M – 20 M Usable 50 – 100 MB
> 20 M Tile architecture territory —

The widget uses Uint16-quantised binary transfer, so a 1 M-point single-cell UMAP normally fits in a < 10 MB HTML file that you can email or commit.

Citation

citation("reglScatterplotR")

Please also cite the underlying JavaScript library: Lekschas, F. (2023). regl-scatterplot: A WebGL-Powered Scatter Plot Renderer. https://github.com/flekschas/regl-scatterplot

Licence

MIT. See LICENSE.