facet-grid

Grid facets: panels on a row x column grid from two discrete variables.

Either rows or columns may be none, but not both. Only shared scales are supported in v1.

Usage

facet-grid(
  rows: none,
  columns: none,
  scales: "fixed",
  labeller: label-value(),
)

Parameters

Parameter Default Description
rows none Name of the discrete column driving panel rows, or none.
columns none Name of the discrete column driving panel columns, or none.
scales "fixed" Scale policy. Only "fixed" is supported in v1.
labeller label-value() Labeller controlling strip text. Defaults to label-value() which shows the level as-is.

Returns

Facet dictionary consumed by plot.

Examples

Two discrete variables driving the row and column structure.

#let d = ()
#for sp in ("a", "b") {
  for sex in ("F", "M") {
    for i in range(0, 5) {
      d.push((sp: sp, sex: sex, x: i, y: i + 1))
    }
  }
}
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  facet: facet-grid(rows: "sex", columns: "sp"),
  width: 12cm,
  height: 7cm,
)

2-by-2 grid of scatter panels with sex (F, M) on the rows and species (a, b) on the columns; each panel shows the same y = x + 1 line.

2-by-2 grid of scatter panels with sex (F, M) on the rows and species (a, b) on the columns; each panel shows the same y = x + 1 line.

Pass only rows: (or only columns:) for a one-dimensional grid layout.

#let d = ()
#for sex in ("F", "M") {
  for i in range(0, 6) {
    d.push((sex: sex, x: i, y: i * 1.5))
  }
}
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  facet: facet-grid(rows: "sex"),
  width: 12cm,
  height: 7cm,
)

Two scatter panels stacked vertically, one row per sex (F, M), both showing the same y = 1.5x line over x = 0 to 5.

Two scatter panels stacked vertically, one row per sex (F, M), both showing the same y = 1.5x line over x = 0 to 5.

See also

facet-wrap, plot.

Back to top