| mark_violin | R Documentation |
Draws the distribution of a numeric variable for each group as a mirrored kernel density curve, trimmed to the range of the group's values. All violins in the mark use the same density scale, so their widths can be compared directly.
Map y to the numeric variable and x to the grouping variable, which
is treated as categorical even when it is numeric. Without x, all rows
form one violin. Mapping color to a different variable than x places
one violin per colour side by side within each x group.
The densities are computed in R when the plot is compiled, with
stats::density(). A group needs at least two distinct values; groups
with fewer are left out with a warning.
mark_violin(
spec,
...,
data = NULL,
style = list(),
bw = "nrd0",
adjust = 1,
width = 0.9
)
spec |
A glyph_spec |
... |
Aesthetic mappings: |
data |
Optional per-mark data override |
style |
Named list of fixed visual properties |
bw |
Smoothing bandwidth, passed to |
adjust |
Multiplier for the bandwidth. Values above 1 give smoother curves. |
width |
Width of the widest violin as a fraction of the space for its group, between 0 and 1. |
Modified glyph_spec object with the violin mark added
glyph(mtcars, x = factor(cyl), y = mpg) |>
mark_violin()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.