help violinplothttps://github.com/benjann/violinplot/

Title

violinplot -- Draw violin plots

Syntax

Syntax 1: Single group of outcome variables

violinplot [(]varlist[)]
[if] [in] [weight]
[,
options
]

Syntax 2: Multiple groups of outcome variables

violinplot (varlist) (varlist) [...]
[if] [in] [weight]
[,
options
]

options

Main
vertical vertical violins

horizontal horizontal violins

left print left half of violin

right print right half of violin

overlay create overlays rather than separate violins

asover treat variable groups as over categories

over(spec) display results by
categories of over-variable

atover use values of over categories as plot positions

swap swap variables and over categories

nostack do not use stacked axis labels, use a legend

gap(#) size of extra gap between groups of results; default is 0.5

split(varname) create half
violins

by(spec) create subgraphs by
categories of by-variable

Estimation
dscale(spec) change the
scaling of the plotted PDFs

absolute use absolute scaling

[l|r]tight use tight density evaluation grid

range(spec) restrict maximum
density evaluation range

n(#) size of evaluation grid; default is n(99)

pdfopts(options) density
estimation options passed through to dstat

qdef(#) quantile definition to be
used by dstat

cw omit observations with missing value on any outcome variable

Labels
labels(strlist) provide custom labels for outcome variables

olabels(strlist) provide custom labels for over categories

slabels(strlist) provide custom labels for splits

bylabels(strlist) provide custom labels for subgraphs

nolabel use names and values, not labels

key(element) plot element to be
used in legend keys

Elements
[no]line[(options)] whether
PDF lines are printed; rendering of PDF lines

[no]fill[(options)] whether
shading is added; rendering of shading

[no]whiskers[(opts)] whether
whiskers are printed; rendering of whiskers

[no]box[(options)] whether
box is printed; rendering of box

[no]median[(opts)] whether
median is printed; rendering of median

mean[(options)] add marker for mean;
rendering of mean

rag[(options)] add markers for data points;
rendering of the rag

order(list) change order in which
elements are printed

offset(numlist) shift position of box plot (and rag)

doffset(numlist) shift position of PDF

Colors
colors(spec) assign colors
to results, affecting all elements

lcolors(spec) like colors(), but only affecting PDF lines

fcolors(spec) like colors(), but only affecting shading

wcolors(spec) like colors(), but only affecting whiskers

bcolors(spec) like colors(), but only affecting box

medcolors(spec) like colors(), but only affecting median

meancolors(spec) like colors(), but only affecting mean

ragcolors(spec) like colors(), but only affecting rag

Other
pstyles(numlist) assign plot styles to results

p#(options) options passed through to #th result (within group)

p#el(options) options passed through to element of #th result (within group)

byopts(byopts) options passed through
to by()

addplot(plot) add other plots to the graph

twoway_options general options passed through to graph twoway

fweights, pweights, and iweights are allowed; see help weight.

Description

violinplot draws so called violin plots that illustrate the
distributions of the specified outcome variables. A violin plot is an
overlay of a (reflected) density estimate and a box plot (Hintze and Nelson
1998).

Technical note: By default (unless option atover is specified),
violinplot deactivates ticks and grid lines on the categorical axis
and sets the gap between the labels and the axis to tiny (mimicking
the behavior of graph box). To print the ticks and gridlines and
to restore the default gap as used by graph twoway, specify
ylabel(, tick grid labgap(half_tiny)) (if in horizontal mode;
in vertical mode use the xlabel() option). If your graph contains
subgraphs, you additionally need to specify byopts(iytick) or
byopts(ixtick).

Alternative implementations of violin plots are provided by command
vioplot (Winter and Nichols 2008) and command violin
(Steichen 1998, 2001). Furthermore, command joy_plot (Rios-Avila
2022) provides functionality for violin plots.

Dependencies

violinplot requires dstat, moremata, palettes,
and colrspace. To install these packages, type:

. ssc install dstat
. ssc install moremata
. ssc install palettes
. ssc install colrspace

Options

Main

vertical draws vertical violins. This is the default if overlay
(but not left or right) or split() is specified.

horizontal draws horizontal violins. This is the default unless
overlay (but not left or right) or split() is specified.

left prints the left half of each violin. The default is to print both
halves.

right prints the right half of each violin. The default is to print both
halves.

overlay overlays the results from several variables or subpopulations. The
default is to print each result individually. Overlay implies vertical,
nowhiskers, and nobox. overlay is not allowed if
split() is specified.

asover treats variable groups (Syntax 2) as over categories. The default
is to create a separate subgraph for each variable group. asover and
over() are not both allowed.

over(varname[, options]) displays subpopulation
results by levels of varname. varname may be numeric or string. Options
are as follows.

total[(str)] includes total results across all
subpopulations. Optional str specifies a custom label; default is "(total)".

missing[(str)] includes results from subpopulations for which
varname is missing; each type of missing value (., .a, .b, etc.)
will be treated as a separate category. The default is to exclude missing
values. Optional str specifies a custom label for system missing (.);
default is "(missing)".

sort[(#)] puts the results in order of their
medians (or in order of the statistic selected by
median(stat())). If there are multiple outcome variables, specify
# to select the relevant variable; the ordering will then be based on
the results from the #th outcome variable (within the first variable
group). Default is to use the first outcome variable.

descending uses descending sort order. The default is to use
ascending sort order. descending implies sort.

tlast always places the total results last, irrespective of sort
order. tlast implies total.

atover uses the values of the over variable to determine the plot
positions of the results rather than placing them along a categorical
axis. atover requires over() and is only allowed in selected
situations. For example, atover cannot be combined with option swap
or with over suboptions total, missing, or sort, and the over variable
must be numeric. Furthermore, atover is allowed with multiple outcome variables
only of overlay is specified; likewise, atover is allowed with a
single outcome variable only if overlay is omitted.

The maximum space consumed by an individual results is set to one unit by default, which
may not be appropriate if atover is specified (depending scaling of
the over variable). Use option dscale() to change the default;
for example, type dscale(2) to consume at most two units; type dscale(0.5)
to consume at most half a unit.

swap changes the arrangement of results. The default is to group
results from multiple outcome variables by over category. Specify
swap to group results from over categories by outcome variable.

nostack causes a legend to be created for the different results within
groups of results. The default is to label each result individually on the
categorical axis, using two levels of labels. This is only relevant
if there are multiple outcome variables and multiple over
categories. nostack also assigns different plot styles to the
results. nostack is not allowed if split() is specified.

gap(#) specifies the size of the extra gap inserted between clusters of
results that are grouped together within the same subgraph. This is only relevant
if there are multiple outcome variables and multiple over categories (and if overlay is
not specified). The default extra gap is 0.5 (i.e. half the size of the space
each result consumes).

split(varname) splits the violins
by the two groups identified by the levels of varname. split()
implies vertical, fill, and nowhiskers, sets the default type of
box() to lines, and sets the default type of median()
to line. Options nostack and overlay are not allowed if
split() is specified.

by(varname[, options]) displays separate subgraphs
for subpopulation results by levels of varname. varname may be
numeric or string. Option by() is only allowed in Syntax 1 (single group
of outcome variables; or in Syntax 2 if option asover is specified). Options are
as follows.

total[(str)] includes total results across all
subpopulations. Optional str specifies a custom label; default is "(total)".

missing[(str)] includes results from subpopulations for which
varname is missing; each type of missing value (., .a, .b, etc.)
will be treated as a separate category. The default is to exclude missing
values. Optional str specifies a custom label for system missing (.);
default is "(missing)".

byopts are options passed through to graph's by() option, which
is internally used to generate the subgraphs; see help by_option.

Estimation

dscale(spec) determines how the density curves are scaled. spec is

[#][, option]

where #>0 is a custom factor by which the default scaling will
be multiplied and option is individual to determine
the scaling for each violin individually, group to determine the
scaling by group of results (i.e. by clusters of results that are grouped
together within the graph), plot to determine the
scaling by series across clusters (i.e. 1st violin in each group, 2nd violin
in each group, etc.), or subgraph to determine the
scaling by subgraph. The default is to determine the scaling
jointly across all results.

You can also specify dscale(.) to omit rescaling. In this case,
the original scale of each PDF will be retained and, if the graph
only includes a single violin (per subgraph) or a single overlay of multiple
violins (per subgraph), axis labels for the scale will be added.

absolute uses absolute scaling such that the area under the PDF
is proportional to the size of the relevant group.

tight limits the density evaluation grid to the range between the observed
minimum to the observed maximum of the relevant data. By default, the range across
which the density is evaluated is slightly larger than the observed range
of the data. Specify tight to remove this extra padding. Specify
ltight to remove the extra padding only on the left; specify
rtight to remove the extra padding only on the right. In any case,
the evaluation grid will not go beyond the limits specified by
range().

range(from [to]) limits the maximum range across which
the PDF will be evaluated. This may be useful if there are outliers in the
data and you want to clip the display to the main part of the data. from
can be specified as . (missing) to set no lower limit; to can be
omitted or specified as . (missing) to set no upper limit.

By default, fast density estimation based on an approximation grid is used
by violinplot to obtain the PDF. However, if range() results
in an evaluation range that is less than half of the original (unrestricted)
evaluation range, violinplot switches to exact estimation of the affected PDF
to prevent approximation error from becoming visible. Specify option pdfopts(exact)
if you want to apply exact estimation in any case.

n(#) sets the size of the density evaluation grid (number of evaluation
points). The default is n(99).

pdfopts(options) provides density estimation options to be passed through to
dstat; see density_options
in help dstat. The same options will be applied used for all results.

qdef(#) sets the quantile definition to be used when computing the median
and the quartiles for the box and whiskers; see option qdef() in
help dstat.

cw specifies casewise deletion. If cw is specified, observations
for which any of the outcome variables are missing are ignored. The default
is to determine the estimation sample for each variable individually.

Labels

labels(strlist) provides a space separated list of custom labels
for the outcome variables. Enclose labels that
contain spaces in double quotes.

olabels(strlist) provides a space separated list of custom labels
for the over categories. If asover is specified (Syntax 2),
olabels() provides labels for the outcome variable groups. Enclose
labels that contain spaces in double quotes.

slabels(strlist) provides a space separated list of custom labels
for the groups by which the violins are split. Enclose labels that contain spaces in
double quotes.

bylabels(strlist) provides a space separated list of custom titles
for the subgraphs. Enclose labels that contain spaces in
double quotes.

nolabel uses names and values rather variable labels and value labels.

key(element) selects the plot element to be used in legend
keys. This is only relevant in cases in which a legend is
displayed. Depending on context, element is one of line,
fill, whiskers, box, median, mean,
or rag (elements that are not plotted will not be available). The default is
key(line) or, if option noline has been specified, the element
that is plotted first.

Elements

[no]line[(options)] determines
whether the PDF lines are printed or not. The default is to print the lines; type
noline to omit the lines. Specify options to affect the rendering of
the lines; see help connect_options. noline implies
fill. noline cannot be combined with fill(select()).

[no]fill[(options)] determines
whether shading is added to the PDF. The default is to omit shading unless
split() is specified. options are as follows.

select(numlist) restricts the set of results to be affected. By
default, shading is added to all results if option fill is
specified. Type, for example, select(2 5) to add shading only to
the 2nd and 5th result (the counting is across all displayed results,
not within groups or subgraphs). Option select() is not allowed if
noline is specified.

area_options are graph options affecting the rendering
of the shading; see help area_options. By default, option fintensity(50) is applied
to the shading; this is skipped if any area_options are
specified. Furthermore, option lcolor(%0) is applied, which will not
be skipped; specify, e.g., fill(lcolor(%100) to override this
setting.

[no]whiskers[(options)] determines
whether the whiskers are printed or not. The default is to print the whiskers
unless overlay or split() is specified. Specify options to affect the
rendering of the whiskers; see help line_options.

[no]box[(options)] determines
whether the IQR box is printed or not. The default is to print the box
unless option overlay is specified. options
are as follows.

type(type) sets the type of plot to by used, where type can
be bar, fill, or lines. The default is
type(bar) unless split() is specified, which prints the box as a
bar. Specify type(fill) to display the box by adding shading to the
density estimate between the lower and upper bounds. Type type(lines)
to display the box as two lines across the density estimate, one for each
bound; this is the default if split() is specified.

Note that twoway plottype rspike, not
rbar, is used to generate the
box in case of type(bar); type, for example,
box(recast(rbar) barwidth(0.1)) to change the
plottype to rbar and use a bar width of 0.1.

Furthermore, note that type(fill) and type(lines) will not
display anything if option range() has been
applied and the selected range is such that the lower or upper
bound lies outside the density evaluation range.

statistics(lo up) selects custom statistics to be used for the
lower and upper bounds of the box. Any statistics supported by
dstat are allowed. Default is stat(p25 p75)
(lower and upper quartile). For example, type stat(p10 p90) to print
a box spanning the range between the 10% quantile and the 90%
quantile. The selected statistics will also affect the computation of the
whiskers (whiskers are defined, in part, as a function of the lower and
upper bounds of the box).

line_options or area_options are graph options affecting the rendering
of the box; see help line_options for type(bar) or type(lines),
and help area_options for type(fill). In case of type(bar),
the default is to apply lwidth(vthick); this is skipped if any
line_options are specified. In case of type(fill), the default is to apply
fintensity(50) and lcolor(%0) to the shading; the former, but not the latter,
will be skipped if any area_options are specified (specify, e.g.,
lcolor(%100) to override the latter). In case of type(lines), the
default is to apply plattern(shortdash); this is skipped if any
line_options are specified.

[no]median[(options)] determines whether
a marker for the median is printed or not. The default is to print the
marker. options are as follows.

type(type) sets the type of plot to by used, where type can
be marker or line. The default is type(marker)
unless split() is specified, which prints the median as a marker. Specify
type(line) to display the median as a line across the density
estimate. This is the default if split() is specified. Note that
type(line) will not display anything if option
range() has been applied and the selected range
is such that median lies outside the density evaluation range.

statistic(statistic) selects a custom statistic to be used instead of the
median. Any statistic supported by dstat is allowed. Default
is stat(median). For example, type stat(hl) to use the
Hodges-Lehmann location measure.

marker_options or line_options are graph options affecting the
rendering of the median; see help marker_options for type(marker)
and help line_options for type(line). In case of type(marker),
the default is to apply options msymbol(O) and
msize(vsmall) if a box of type bar is displayed, and to apply
mcolor(white) if a box of type bar is displayed and medcolors() is
not specified; these defaults are skipped if any marker_options are
specified.

mean[(options)] prints a marker for the
mean. options are as follows.

type(type) sets the type of plot to by used, where type can
be marker or line. The default is
type(marker), which prints the mean as a marker. Specify type(line)
to display the mean as a line across the density estimate. Note that type(line)
will not display anything if option range() has been
applied and the selected range is such that mean lies outside the density
evaluation range.

statistic(statistic) selects a custom statistic to be used instead of the
mean. Any statistic supported by dstat is allowed. Default
is stat(mean) (arithmetic mean). For example, type stat(trim(5)) to use
the 5% trimmed mean.

marker_options or line_options are graph options affecting the
rendering of the mean; see help marker_options for type(marker)
and help line_options for type(line). In case of type(marker),
if split() is omitted, the default is to apply options msymbol(pipe),
msize(huge), and, depending on context, msangle(90); if
split() is specified, the default is to apply msymbol(x). These
defaults are skipped if any marker_options are specified.

rag[(options)] prints a rag of markers, one marker for each
data point. options are as follows.

outsides only includes outside values, that is, data points that are
smaller (larger) than the lower (upper) limit of the lower (upper)
whisker. The default is to include all data points.

boutsides includes values that are smaller (larger) than the lower
(upper) limit of the box. boutsides implies outsides.

unique omits markers for repeated data points and, unless
noweight is specified, scales marker sizes in proportion to the
number (or sum of weights) of represented observations.

noweight uses the same size for all markers even if weights have been
applied or if points have been collapsed by unique. By default, if
weights are applied or if unique is specified, marker sizes (in terms
of covered area) are scaled in proportion to the represented data mass. The scaling
will be such that the average weight (within
observations used to compute a specific result) corresponds to the default
(unweighted) marker size (unless the largest weight exceeds 100 times the
average, in which case the average-weight marker size will decrease). Specify
noweight if you want to use the same size for each marker.

offset(numlist) shifts the position of the rag(s) by the specified
value(s). The default is to shift the rag(s) as set by the global
offset() option. Use suboption offset()
to override this default (i.e., if you want to use different offsets for
box plots and rags).

spread[(#1 [#2])] spreads out the markers by
adding beta distributed random errors to their positions. At each level of
the data, the error distribution will be scaled in proportion
to the density estimate at that level (such that the rag mimics the shape of the
violin). Argument #1 in [0.001, 100] sets the degree of
spreading; #1=100 (maximum spreading) is equivalent to using
a uniform error distribution; the default is #1=1
(moderate spreading).

Optional argument #2 sets the width of the spread to a fixed value
rather than making the spread proportional to the density estimate. Specify
#2 if you want to generate a uniform rag rather than a rag that mimics
the shape of the violin. Unless dscale(.) is specified, argument
#2 is in units of the space allocated to each violin
(or half-violin). For example, type rag(spread(100 0.2)) to generate
a uniform rag that has a width of 20 percent (argument #1 is set to
100 in this example so that the markers are spread out uniformly across
the width). If dscale(.) is specified, argument #2 is in
absolute units (or half-units).

stack[([*]#)] prints stacks of markers at the unique
values of the data. Use this option to create raindrop plots. Argument
# sets the step size between markers within stacks. A suitable value for the step
size is determined from the data if # is omitted or set to missing. Type
*# to multiply the default step size by #. Only
one of stack() and spread() is allowed.

left spreads the rag in direction of the left half of the violin. The
default is to spread in both directions. Suboption left is implied if
global option left or global option split() is specified. Specify
suboption right, or both left and right, to override this behavior.

right spreads the rag in direction of the right half of the violin. The
default is to spread in both directions. Suboption right is implied if
global option right is specified. Specify suboption
left, or both left and right, to override this behavior.

marker_options are graph options affecting the rendering of the
markers; see help marker_options. By default, options
msymbol(pipe) and, depending on context, msangle(90) are
applied; you can override the default by specifying these options
explicitly.

order(list) changes the order in which the elements are placed on the
plot (determining whether an element is in the foreground or in the
background). list is a space separated list of elements, where an element
is one of line, fill, whiskers, box, median,
mean, and rag (each element can only be listed once; only elements that are
included in the plot are allowed). Elements not included in the list will be
added last (in their default order). The default order depends on context.

offset(numlist) shifts the position(s) of the elements of the box plot(s)
(whiskers, box if type is bar, median if type is marker, mean
if type is marker) by the specified value(s). The default is to place each box plot
at the center of the corresponding violin. A positive value shifts the box plot to the left side of
the violin; a negative value shifts the box plot to the right. A violin
typically consumes space of up to one unit, so that values between -0.5 and 0.5
usually make sense. Specify multiple values
to use different values by physical plots; values will be recycled if numlist has
less elements than there are physical plots. A physical plot is a series of results
drawn by a single plot command; see pstyles() for details
on physical plots.

Note on usage of offset() together with split(): If split()
is specified, a negative value shifts the box plot into the
relevant half violin (and a positive value shifts the box plot into the
other half), and a default offset of about 1% of the range of
the categorical axis is applied (so that the box plots of the two halves
are not printed on top of each other). You can override this default by providing
custom values(s) in offset().

doffset(numlist) shifts the position(s) of the PDF(s) (line and fill) by
the specified value(s). The default is to center each violin at the corresponding
tick of the categorical axis. A positive value shifts the violin up/to the
left; a negative value shifts the violin down/to the right. Specify multiple values
to use different values by physical plots; values will be recycled if numlist has
less elements than there are physical plots. A physical plot is a series of results
drawn by a single plot command; see pstyles() for details
on physical plots.

Colors

colors(spec) assigns colors to the results, affecting all elements
of the violin plot (except the median depending on context). The colors will
be recycled across groups of results and across subgraphs. spec is

palette [, palette_options]

where palette is any palette or color specification compatible with
colorpalette and palette_options are options passed through to
colorpalette. The correct number of colors will be retrieved automatically;
option n() is not allowed. Specify a single color to use the same color
for all variables.

lcolors(spec) is like colors(), but only affects the PDF lines.

fcolors(spec) is like colors(), but only affects the shading.

wcolors(spec) is like colors(), but only affects the whiskers.

bcolors(spec) is like colors(), but only affects the IQR box.

medcolors(spec) is like colors(), but only affects the median.

meancolors(spec) is like colors(), but only affects the mean.

ragcolors(spec) is like colors(), but only affects the rag.

Other

pstyles(numlist) determines the plot styles applied to the
results. If pstyles() is omitted, the default is to use style p1
for all results or, if overlay or nostack is specified, to use
consecutive styles across groups of results (i.e. p1 for the first result
within each group, p2 for the second result within each group,
etc.). For example, specify pstyles(5 3 7) to use p5 for the
first result, p3 for the second result, and p7 for the third
result. If split() is specified, only two styles will be used.

Technically, the styles specified in pstyles() are applied one after
another to the physical plots in the graph, recycling styles
if numlist contains fewer elements than there are physical
plots. A physical plot is a series of results drawn by a single plot
command. If there is only a single group of results, each result is a
separate physical plot. If there are multiple groups of results, physical plots
are organized by positions within group (i.e., all first results are a single
physical plot, all 2nd results are a single physical plot, and so on). If
option split() is specified, all left halves
are a single physical plot and all right halves are a single physical plot.

p#(options) are graph options to be passed through
to the #th physical plot.

p#el(options) are graph options to be passed
through to element el of the #th physical plot. Depending on context,
el is one of l (PDF lines),
f (shading of PDF), w (whiskers), b (box), med (median),
mean, and rag (only elements that are included in the plots are
allowed). For example, type p2med(mcolor(red)) to print the median
marker of each 2nd result per group in red.

byopts(byopts) are options passed through to the by() option,
which is internally used to generate subgraphs; see help by_option.

addplot(plot) allows adding more graph twoway plots to the graph;
see help addplot_option.

twoway_options are general options passed through to graph twoway; see
help twoway_options.

Examples

Basic examples:

. sysuse nlsw88
. violinplot wage ttl_exp tenure
. violinplot wage ttl_exp tenure, nobox
. violinplot wage ttl_exp tenure, mean

. violinplot wage ttl_exp tenure, nobox mean(msymbol(X) msize(large) mcolor(maroon))

. violinplot wage ttl_exp tenure, box(recast(rbar) fintensity(50) barwidth(.15)) median(msymbol(d))

. violinplot wage ttl_exp tenure, vertical
. violinplot wage ttl_exp tenure, pstyles(1/3)

. violinplot wage ttl_exp tenure, range(. 31) plotregion(margin(r=0))

. violinplot wage ttl_exp tenure, fill
. violinplot wage ttl_exp tenure, noline
. violinplot wage ttl_exp tenure, fill(select(3))

Use option pdfopts() to specify density estimation options. For
example, wages, work experience, and tenure cannot be negative, so let's apply boundary
correction at zero:

. violinplot wage ttl_exp tenure, pdf(ll(0))

Use option over() to display results by subpopulations:

. violinplot wage, pdf(ll(0)) over(union)
. violinplot wage ttl_exp tenure, pdf(ll(0)) over(union)
. violinplot wage ttl_exp tenure, pdf(ll(0)) over(union) swap

. violinplot wage ttl_exp tenure, pdf(ll(0)) over(union) swap nostack

. violinplot wage, pdf(ll(0)) over(industry, sort tlast) nobox nowhiskers

Use option by() to create subgraphs by subpopulations:

. violinplot wage ttl_exp tenure, pdf(ll(0)) by(union)

Combination of over() and by():

. violinplot wage ttl_exp tenure, pdf(ll(0)) over(race) by(union)

. violinplot wage ttl_exp tenure, pdf(ll(0)) over(race) by(union) swap

Use parentheses to define groups of variables that will be placed in separate
subgraphs:

. violinplot (wage) (ttl_exp), over(race)

Use option overlay to create overlays (whiskers and boxes will be omitted by default):

. violinplot wage ttl_exp tenure, pdf(ll(0)) over(union) overlay swap

. violinplot wage ttl_exp tenure, pdf(ll(0)) over(union) overlay swap noline fill(color(%30)) key(median)

Use option split() to create half violins (whiskers will be omitted,
lines will be used to display box and median, and fill will be added by default):

. violinplot wage ttl_exp tenure, pdf(ll(0)) split(union) key(fill)

. violinplot wage tenure, pdf(ll(0)) over(south) swap gap(0) split(union) absolute

Use options colors() (all elements), lcolors() (PDF lines), bcolors()
(boxes), etc., to obtain colors from colorpalette:

. violinplot wage ttl_exp tenure, pdf(ll(0)) over(union) swap nostack colors(Set1)

. violinplot wage, over(industry) colors(sb muted) nobox nowhiskers median(msymbol(o))

. violinplot wage, over(industry) colors(sb muted) box(type(fill)) median(msymbol(o) msize(vsmall) color(white)) nowhiskers

. violinplot wage, over(industry, descending) colors(plasma) fill nobox nowhiskers nomedian

Print data points using option rag():

. violinplot wage, left rag(offset(-.005) mlcolor(%20)) dscale(.)

. violinplot wage, left rag(offset(-.005) spread right) dscale(.) ylabel(0(.05).15)

. sysuse auto, clear

. violinplot price, over(foreign) vertical fill rag(spread(5) msymbol(o) mcolor(maroon%50) mlcolor(%0))

References

Hintze, J.L., R.D. Nelson
(1998). Violin Plots: A Box Plot-Density Trace Synergism. The
American Statistician 52:181-184.

Rios-Avila, F. (2022). JOY_PLOT: Stata module to produce joy plots. Available
from https://ideas.repec.org/c/boc/bocode/s459066.html.

Steichen, T.J. (1998). gr33: Violin plots. Stata Technical Bulletin 46:13-18.

Steichen, T.J. (2001). gr33.1: Violin plots for Stata 6 and 7. Stata Technical Bulletin 61:10.

Winter, N., A. Nichols (2008). VIOPLOT: Stata module to produce violin plots
with current graphics. Available from
https://ideas.repec.org/c/boc/bocode/s456902.html.

Author

Ben Jann, University of Bern, ben.jann@unibe.ch

Thanks for citing this software as follows:

Jann, B. (2022). VIOLINPLOT: Stata module to draw violin plots. Available from
https://ideas.repec.org/c/boc/bocode/s459132.html.

Also see

Online: help for graph twoway, graph box