Botany

Violin plot example: iris petal length

Violin plot of petal length for three iris species, 50 flowers each, with a narrow type-7 box inside. Bandwidths follow R bw.nrd0 and are listed per species.

Open this example in the editorStart from scratch

02468Petal length (cm)setosa (n = 50)versicolor (n = 50)virginica (n = 50)
Petal length of 150 iris flowers; violins show Gaussian kernel densities and boxes show type-7 quartiles (50 flowers per species).

About this example

Edgar Anderson measured the flowers that R ships as datasets::iris, and Fisher used them in 1936. Petal length separates the species clearly: setosa petals cluster between 1.0 and 1.9 cm, while versicolor and virginica overlap between about 4.5 and 5.1 cm. With 50 flowers per species, a violin has enough values to show where they pile up.

Each violin uses its own automatic bandwidth, R’s bw.nrd0: about 0.054 cm for setosa, 0.18 cm for versicolor and 0.23 cm for virginica. The narrow setosa outline is therefore a real feature of the data, not a drawing choice. Equal-area scaling, the default, gives every species the same violin area, so a tall narrow violin and a short wide one hold the same share of flowers.

Petal lengths are recorded to 0.1 cm, so up to 13 setosa flowers share one value. This example opens with points hidden, because 50 tied dots do not fit side by side in an 85 mm figure; switch Observations to “All observations” on a wider figure to show every flower. The narrow box marks the median and quartiles, and the editor’s summary table lists each bandwidth so it can be quoted in a figure legend.

Sources: R datasets::iris — Anderson (1935), Fisher (1936)

The data

SpeciesPetal length (cm)
setosa1.4
setosa1.4
setosa1.3
setosa1.5
setosa1.4
setosa1.7
setosa1.4
setosa1.5
setosa1.4
setosa1.5
setosa1.5
setosa1.6
setosa1.4
setosa1.1
setosa1.2

…and 135 more rows. Open the example to see all of them.

These are individual observations, not supplied group summaries. The editor reports its interpretation and preserves your selected presentation when loading an example. Open the example, replace the data with your own, and export the figure as SVG, PDF, PNG or TIFF.

More examples