Skip to contents

A GPU-accelerated 2-D scatter viewer for dimensionality-reduction output. Points are rendered with WebGL (via regl-scatterplot) so hundreds of thousands to millions of cells stay interactive at 60fps, while the legend and an optional axis frame are drawn as crisp vector overlays. Lasso selection is enabled (drag from empty space to select points).

Usage

embedding(
  data,
  point_size = 3,
  point_scale_mode = c("asinh", "linear", "constant"),
  opacity = 0.8,
  color_mode = c("auto", "categorical", "continuous"),
  colormap = c("viridis", "rdbu"),
  mouse_mode = c("panZoom", "lasso"),
  aspect = c("fill", "equal"),
  padding = 0.04,
  x_label = "UMAP 1",
  y_label = "UMAP 2",
  show_axes = FALSE,
  show_legend = TRUE,
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL
)

Arguments

data

A data frame with numeric columns x and y (the embedding coordinates). An optional color column drives coloring: a character or factor column is treated as categorical (discrete legend), a numeric column as continuous (sequential colormap + colorbar). A factor color fixes the legend order and the color assignment to its levels, and keeps unused levels in the legend, the way drop = FALSE does in ggplot2. An optional label column supplies per-point tooltip text.

point_size

Point radius in pixels. Under the default point_scale_mode the renderer scales this by the camera and clamps it to one pixel on a widely-scaled plot, so set point_scale_mode = "constant" if you want it honoured literally.

point_scale_mode

How point_size responds to zoom. "asinh" and "linear" shrink points as you zoom out, which keeps a dense embedding readable, but both floor at one pixel once the camera scale drops below 1 / point_size. "constant" sizes points in literal pixels.

opacity

Point opacity in [0, 1].

color_mode

How to interpret the color column: "auto" detects from its type, or force "categorical" / "continuous".

colormap

Sequential color ramp for continuous coloring: "viridis" or "rdbu".

mouse_mode

Primary drag gesture: "panZoom" (default) pans/zooms and "lasso" makes a plain drag draw a selection.

aspect

How the fitted view maps data units onto pixels. "fill" stretches each axis to fill the canvas, which suits a UMAP, whose axes carry no units. "equal" gives both axes the same units per pixel; use it when the axes share units and their relative spread is part of the claim, as in PCA scores.

padding

Fraction of the data range to pad around the fitted view. Larger values zoom out, leaving more empty space at the edges, which stops the outermost points being clipped by the canvas border.

x_label, y_label

Axis titles (shown when show_axes = TRUE).

show_axes

Draw the axis frame + ticks (embeddings usually hide axes).

show_legend

Draw the legend (discrete swatches or a colorbar).

theme

Optional named list of theme overrides (colors, fonts, ...) merged over the component defaults in the browser. NULL uses the default theme.

width, height

Widget dimensions (any valid CSS size).

element_id

Optional explicit DOM id.

Value

An htmlwidget object.

Examples

set.seed(1)
n <- 5000
k <- sample(0:5, n, replace = TRUE)
df <- data.frame(
  x = rnorm(n) + k * 4,
  y = rnorm(n) + (k %% 2) * 4,
  color = paste0("cluster ", k + 1),
  label = paste0("cell", seq_len(n))
)
embedding(df)