boxplot
lq.boxplot(..data, x: auto, whisker-pos: 1.5, width: 50%, fill: none, stroke: 1pt + black, median: 1pt + orange, mean: none, whisker: auto, cap: auto, cap-length: 0.25, outliers: "o", outlier-size: 5pt, outlier-fill: none, outlier-stroke: black, label: none, clip: true, z-index: 2)(source)Computes and visualizes one or more boxplots from datasets.
In the following example, boxplots are generated for four different datasets. The default boxplot visualizes the first and third quartil as well as the median of the data with a box and shows traditional whiskers and outliers.
#lq.diagram(
lq.boxplot(
stroke: blue.darken(50%),
(1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 19),
range(1, 30),
(1, 28, 25, 30),
(1, 2, 3, 4, 5, 6, 32),
)
)
Boxplots can be richly customized as demonstrated below.
#let data = (-3, -5, 1, 3, 3, 3, 4, 4, 2, 6, 10, 11)
#lq.diagram(
lq.boxplot(
data,
stroke: luma(30%),
fill: yellow,
),
lq.boxplot(
data, x: 2,
whisker: blue,
cap: red,
cap-length: 0.7,
median: green
),
lq.boxplot(data, x: 3, outliers: "x"),
lq.boxplot(data, x: 4, outliers: none),
)
Although Lilaq uses Komet to
compute the boxplot, some data sets might be too large to be processed in
Typst. In this case, the median, the whiskers, the first and the third
quartil can be computed with an external tool and specified manually
(see also boxplot.data).
#lq.diagram(
width: 4cm,
margin: (x: 50%),
lq.boxplot(
(
median: 4.4,
q1: 2,
q3: 8,
outliers: (12, 13),
whisker-low: 0,
whisker-high: 10,
),
)
)
..data : array | dictionary
One or more data sets to generate a boxplot from. A data set can either be
- an array of values (in this case all statistics are computed automatically) or
- a dictionary with the mandatory keys
median,q1,q3,whisker-low, andwhisker-highand optional keysmeanandoutliers. This method is useful for precomputed distributions, especially data sets that are too large for processing in Typst.
x : auto | int | float | array default: auto
The coordinate(s) to draw the boxplots at. If set to auto, boxplots will
be created at integer positions starting with 1.
whisker-pos : int | float default: 1.5
The position of the whiskers. The length of the whiskers is at most
whisker-pos * (q3 - q1) where q1 and q3 are the first and third quartils.
However, the whiskers always end at an actual data point, so the length can be
less then that. The default value of 1.5 is a very common convention established
by John Tukey in Exploratory data analysis (1977).
width : ratio | int | float | duration | array default: 50%
The width of the boxplots in data coordinates. See bar.width.
fill : none | color | gradient | tiling default: none
How to fill the boxes.
stroke : length | color | stroke | gradient | tiling | dictionary default: 1pt + black
How to stroke the boxplot in general. Also see boxplot.whisker, boxplot.cap.
median : length | color | stroke | gradient | tiling | dictionary default: 1pt + orange
How to stroke the line that indicates the median of the data.
mean : none | lq.mark | str | stroke default: none
By default, the mean value is not shown but it can be visualized with a mark or a line like the median.
#lq.diagram(
margin: (x: 20%),
lq.boxplot((1, 3, 10), mean: "."),
lq.boxplot((1, 3, 10), mean: green, x: 2),
)
whisker : auto | length | color | stroke | gradient | tiling | dictionary default: auto
How to stroke the whiskers. If set to auto, the stroke is inherited from
boxplot.stroke.
cap : auto | length | color | stroke | gradient | tiling | dictionary default: auto
How to stroke the caps of the whiskers. If set to auto, the stroke is inherited
from boxplot.stroke.
cap-length : int | float default: 0.25
The length of the whisker caps in data coordinates.
outliers : none | lq.mark | str default: "o"
Whether and how to display outliers. See plot.mark.
outlier-size : length default: 5pt
The size of the marks used to visualize outliers.
outlier-fill : none | auto | color default: none
How to fill outlier marks.
outlier-stroke : stroke default: black
How to stroke outlier marks.
label : content default: none
The legend label for this plot. See plot.label.
clip : bool default: true
Whether to clip the plot to the data area. See plot.clip.
z-index : int | float default: 2
Determines the position of this plot in the order of rendered diagram
objects. See plot.z-index.