Skip to main content

boxplot

lq.boxplot(..data, x=auto, whisker-pos=1.5, width=0.5, 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),
)
)

By default, the mean value is not shown but it can be visualized by setting the boxplot.mean parameter to a mark or line stroke.

#lq.diagram(
lq.boxplot((1, 3, 10), mean: "."),
lq.boxplot((1, 3, 10), mean: green, x: 2),
)

Boxplots can be richly customized as demonstrated below.

#lq.diagram(
lq.boxplot(
(1, 3, 10),
stroke: luma(30%),
fill: yellow,
median: red
),
lq.boxplot(
(1.5, 3, 9),
x: 2,
whisker: blue,
cap: red,
cap-length: 0.7,
median: green
),
lq.boxplot(
lq.linspace(5.3, 6.2) + (2, 3, 7, 9.5),
x: 3,
outliers: "x"
),
lq.boxplot(
lq.linspace(5.3, 6.2) + (2, 3, 7, 9.5),
x: 4,
outliers: none
),
)

Some data sets might be too large to be processed in Typst. In this case, the median, the first and third quartil as well as the whiskers can be computed somewhere else and specified manually in Lilaq (see also boxplot.data).

#lq.diagram(
width: 4cm,
lq.boxplot(
(
median: 4.4,
q1: 2,
q3: 8,
outliers: (12, 13),
whisker-low: 0,
whisker-high: 10,
),
)
)
Parameters

..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, and whisker-high and optional keys mean and outliers. 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 xx 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 : int | float | array    default: 0.5

The width of the boxplots in xx data coordinates. This can be a constant width applied to all boxplots or an array of widths matching the number of data sets.

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

Whether and how to display the mean value. The mean value can be visualized with a mark (see plot.mark) or a line like the median.

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 xx 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 zz position of this plot in the order of rendered diagram objects. See plot.z-index.