One row per feature, one violin per group. A box plot hides bimodality, which in single-cell data is usually the whole story: a gene expressed in half a cluster and silent in the other half has the same median as one expressed weakly everywhere. The violin shows the shape, and stacking rows on a shared x lets a marker panel be read down the page.
Usage
violin(
data,
grid,
density,
grids = NULL,
median = NULL,
features = NULL,
groups = NULL,
group_colors = NULL,
violin_width = 0.85,
scale_per_violin = FALSE,
show_median = TRUE,
show_feature_labels = TRUE,
theme = NULL,
width = NULL,
height = NULL,
element_id = NULL
)Arguments
- data
A data frame with
featureandgroupkey columns, one row per violin, in the order to draw them.- grid
Numeric vector, the shared evaluation grid, ascending.
- density
Numeric matrix, violins x
grid, of density values.- grids
Optional numeric matrix, features x
grid, giving each feature its own y range. Without it every row sharesgrid, which lets one highly expressed feature compress the rest into flat lines.- median
Optional numeric vector, one median per violin, drawn as a tick.
- features, groups
Character vectors fixing the row and column order. Factor
feature/groupcolumns supply them from their levels.- group_colors
One hex colour per group.
NULLuses the categorical palette.- violin_width
Fraction of a cell's width the widest violin fills.
- scale_per_violin
Scale each violin to its own maximum rather than the row's. Per-row is the default so groups stay comparable within a feature.
- show_median, show_feature_labels
Toggle the median tick and row labels.
- theme
Optional named list of theme overrides.
- width, height
Widget dimensions (any valid CSS size).
- element_id
Optional explicit DOM id.
Details
The widget draws densities, it does not estimate them. Each violin arrives as
a vector of density values on a shared grid, because kernel bandwidth choice
changes what the figure claims and belongs with the data. violin_density()
computes them from raw values with stats::density().
Examples
d <- violin_density(list(`CD3D|T` = rnorm(50, 2), `CD3D|B` = rnorm(50, 0)))
violin(d$data, grid = d$grid, density = d$density, median = d$median)