boxplot
boxplot(x, y; kwargs...)
Draw a Tukey style boxplot. The boxplot has 3 components:
a
crossbar
spanning the interquartile (IQR) range with a midline marking the medianan
errorbar
whose whiskers spanrange * iqr
points marking outliers, that is, data outside the whiskers
Arguments
x
: positions of the categoriesy
: variables within the boxes
Keywords
weights
: vector of statistical weights (length of data). By default, each observation has weight1
.orientation=:vertical
: orientation of box (:vertical
or:horizontal
)width=1
: width of the box before shrinkinggap=0.2
: shrinking factor,width -> width * (1 - gap)
show_notch=false
: draw the notchnotchwidth=0.5
: multiplier ofwidth
for narrowest width of notchshow_median=true
: show median as midlinerange
: multiple of IQR controlling whisker lengthwhiskerwidth
: multiplier ofwidth
for width of T's on whiskers, or:match
to matchwidth
show_outliers
: show outliers as pointsdodge
: vector ofInteger
(length of data) of grouping variable to create multiple side-by-side boxes at the samex
positiondodge_gap = 0.03
: spacing between dodged boxes
Examples
using CairoMakie
xs = rand(1:3, 1000)
ys = randn(1000)
boxplot(xs, ys)
using CairoMakie
xs = rand(1:3, 1000)
ys = randn(1000)
dodge = rand(1:2, 1000)
boxplot(xs, ys, dodge = dodge, show_notch = true, color = dodge)
Colors are customizable. The color
attribute refers to the color of the boxes, whereas outliercolor
refers to the color of the outliers. If not scalars (e.g. :red
), these attributes must have the length of the data. If outliercolor
is not provided, outliers will have the same color as their box, as shown above.
Note
For all indices corresponding to points within the same box, color
(but not outliercolor
) must have the same value.
using CairoMakie
xs = rand(1:3, 1000)
ys = randn(1000)
dodge = rand(1:2, 1000)
boxplot(xs, ys, dodge = dodge, show_notch = true, color = map(d->d==1 ? :blue : :red, dodge) , outliercolor = rand([:red, :green, :blue, :black, :yellow], 1000))
Using statistical weights
using CairoMakie, Distributions
N = 100_000
x = rand(1:3, N)
y = rand(Uniform(-1, 5), N)
w = pdf.(Normal(), x .- y)
fig = Figure()
boxplot(fig[1,1], x, y)
boxplot(fig[1,2], x, y, weights = w)
fig
These docs were autogenerated using Makie: v0.19.12, GLMakie: v0.8.12, CairoMakie: v0.10.12, WGLMakie: v0.8.16