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", "ltc", "ltcdiv"),
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,
bounded_view = TRUE,
theme = NULL,
width = NULL,
height = NULL,
element_id = NULL
)Arguments
- data
A data frame with numeric columns
xandy(the embedding coordinates). An optionalcolorcolumn drives coloring: a character or factor column is treated as categorical (discrete legend), a numeric column as continuous (sequential colormap + colorbar). A factorcolorfixes the legend order and the color assignment to its levels, and keeps unused levels in the legend, the waydrop = FALSEdoes in ggplot2; character categories are sorted in natural order ("cluster 2" before "cluster 10"). A missingcoloris drawn grey and keyed "NA", and a row with a missingxoryis not drawn. An optionallabelcolumn supplies per-point tooltip text.- point_size
Point radius in pixels. Under the default
point_scale_modethe renderer scales this by the camera and clamps it to one pixel on a widely-scaled plot, so setpoint_scale_mode = "constant"if you want it honoured literally.- point_scale_mode
How
point_sizeresponds 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 below1 / point_size."constant"sizes points in literal pixels.- opacity
Point opacity in
[0, 1].- color_mode
How to interpret the
colorcolumn:"auto"detects from its type, or force"categorical"/"continuous".- colormap
Color ramp for continuous coloring:
"viridis","rdbu","ltc"(an earthy teal to sand to rust sequential ramp) or"ltcdiv"(its diverging counterpart, neutral cream at the midpoint).- 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).
- bounded_view
Keep pan and zoom inside the data: zooming out stops at the view that shows all of it, a pan stops at its edges, and zooming in stops at 1/10,000 of its range.
FALSElets the view move freely. Either way a double-click, or the reset button in the top right corner of the plot, goes back to the view of all the data. A double-click also clears the lasso selection.- theme
Optional named list of theme overrides (colors, fonts, ...) merged over the component defaults in the browser.
NULLuses the default theme. Itspaddingentry is the space in px between the edge of the widget and the plot: one number for every side, or numbers namedtop,right,bottomandleftin a list or vector, a side left out keeping the default of 10. Itscategoricalentry is an ordered palette: the colours go to the categories in order, and names on the colours are not matched to them. A colour given as a CSS custom property, such asbackground = "var(--bg)", takes the value the page gives it when the plot draws. After the page changes the property, what the plot drew on a canvas keeps the old colour until it draws again: resize the widget or render it again.- width, height
Widget dimensions (any valid CSS size).
- element_id
Optional explicit DOM id.