VISUALISE species AS x, bill_dep AS y FROM ggsql:penguins
DRAW violinViolin
Layers are declared with the
DRAWclause. Read the documentation for this clause for a thorough description of how to use it.
Violin plots display the distribution of a single continuous variable for multiple groups. The violins are mirrored kernel density estimates, similar to the density layer, but organised as distinct groups.
Aesthetics
The following aesthetics are recognised by the violin layer.
Required
x: Position on the x-axis (categorical).y: Value on the y-axis for which to compute density.
Optional
stroke: The colour of the contour lines.fill: The colour of the inner area.colour: Shorthand for settingstrokeandfillsimultaneously.opacity: The opacity of the colours.linewidth: The width of the contour lines.linetypeThe dash pattern of the contour line.
Settings
position: Determines the position adjustment to use for the layer (default is'dodge')bandwidth: A numerical value setting the smoothing bandwidth to use. If absent (default), the bandwidth will be computed using Silverman’s rule of thumb.adjust: A numerical value as multiplier for thebandwidthsetting, with 1 as default.kernel: Determines the smoothing kernel shape. Can be one of the following:'gaussian'(default)'epanechnikov''triangular''rectangular'or'uniform''biweight'or'quartic''cosine'
width: Relative width of the violins. Defaults to0.9.
Data transformation
A violin layer uses the same computation as a density layer. See the density data transformation section for details. The major difference between a violin layer and a density layer is just the matter of display.
Properties
weight: If mapped, it sets the relative contribution of an observation to the density estimate.
Calculated statistics
density: The estimated probability density per point on the grid. The total area of a single density curve adds up to 1.intensity: Also termed ‘probability intensity estimation’, it is the precursor of thedensityvariable. Specifically it is the same as the density without normalisation. You can useREMAPPING intensity AS offsetif you want to reflect differences in group sizes.
Default remappings
density AS offset: By default the offsets around a centerline reflect the computed density.
Examples
A typical violin plot.
The adjust setting controls the smoothing.
VISUALISE species AS x, bill_dep AS y FROM ggsql:penguins
DRAW violin SETTING adjust => 0.1To more clearly indicate differences in group sizes, you can use the intensity computed variable. Note that we have fewer (n=68) Chinstrap penguins than Adelie (n=152) or Gentoo (n=124) penguins.
VISUALISE species AS x, bill_dep AS y FROM ggsql:penguins
DRAW violin REMAPPING intensity AS offsetYou can combine groups to expand the categories.
VISUALISE species AS x, bill_dep AS y, island AS fill FROM ggsql:penguins
DRAW violin