coord-fixed

Cartesian coordinate system with a fixed data-unit aspect ratio.

The user’s width and height act as upper bounds: the renderer keeps the smaller of the two derived panel dimensions and shrinks the longer axis so that one x data unit projects to ratio y data units.

Usage

coord-fixed(
  ratio: 1,
)

Parameters

Parameter Default Description
ratio 1 Number of y data units per x data unit (default 1).

Returns

Coordinate dictionary consumed by plot.

Examples

One x unit equals one y unit, useful for spatial data where the axes share units.

#let d = range(0, 20).map(i => (x: i, y: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  coord: coord-fixed(ratio: 1),
  width: 10cm,
  height: 6cm,
)

Scatter chart of x = 0 to 19 against y = x/2 with a 1:1 aspect ratio so the panel shrinks to keep one x unit equal to one y unit.

Scatter chart of x = 0 to 19 against y = x/2 with a 1:1 aspect ratio so the panel shrinks to keep one x unit equal to one y unit.

ratio: 0.5 makes y units half the size of x units, useful for stretching tall data into a wide panel.

#let d = range(0, 20).map(i => (x: i, y: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-line(stroke: 1pt), geom-point(size: 2pt)),
  coord: coord-fixed(ratio: 0.5),
  width: 10cm,
  height: 6cm,
)

Line with points along y = x/2 from x = 0 to 19 drawn with y units half the size of x units, stretching the trend horizontally.

Line with points along y = x/2 from x = 0 to 19 drawn with y units half the size of x units, stretching the trend horizontally.

See also

plot, coord-cartesian.

Back to top