mpg
Fuel economy of 30 cars (small fuel-economy reference dataset).
Each row is one vehicle. Columns:
manufacturer(string).model(string).displ(engine displacement, litres).cyl(number of cylinders).class(vehicle class, e.g.,"compact","midsize","suv").cty(city miles per gallon).hwy(highway miles per gallon).
The bundled literal is stored in column-store form; plot accepts either column-store or row-store input and normalises internally.
Source: subset of the mpg dataset bundled with the ggplot2 R package; see help("mpg") in R. Originally extracted from the US Environmental Protection Agency’s fuel economy data, https://fueleconomy.gov/, restricted to models with a new release every year between 1999 and 2008.
Usage
mpgExamples
Preview the first ten entries (out of 30).
#let cols = mpg.pairs()
#let cell(v) = if v == none { text(fill: gray, [_none_]) } else { [#v] }
#table(
columns: cols.len(),
align: center + horizon,
inset: 5pt,
stroke: 0.5pt,
..cols.map(p => strong(raw(p.at(0)))),
..range(10).map(i => cols.map(p => cell(p.at(1).at(i)))).flatten(),
)Highway mpg vs engine displacement, filled by vehicle class.
#plot(
data: mpg,
mapping: aes(x: "displ", y: "hwy", fill: "class"),
layers: (geom-point(size: 3pt),),
width: 11cm,
height: 7cm,
)Facet by class and add a linear smoother per panel to compare per-class trends.
#plot(
data: mpg,
mapping: aes(x: "displ", y: "hwy"),
layers: (
geom-point(size: 2pt),
geom-smooth(method: "lm", se: false),
),
facet: facet-wrap("class", ncolumn: 3),
width: 12cm,
height: 7cm,
)