breaks-width

Breaks spaced a fixed distance apart.

Since 0.6.0.

Covers the data range with positions offset + k * width, so the ticks stay on round multiples however the domain moves. The counterpart of scales::breaks_width().

Usage

breaks-width(
  width,
  offset: 0,
)

Parameters

Parameter Default Description
width Distance between consecutive breaks; must be positive.
offset 0 Value the sequence is anchored on, i.e. every break is offset plus a whole multiple of width.

Returns

Closure taking the trained values and returning break positions.

Examples

A tick every 2.5 miles per gallon, whatever the trained range.

#plot(
  data: mpg,
  mapping: aes(x: "displ", y: "hwy"),
  layers: (geom-point(),),
  scales: scales(y: scale-continuous(breaks: breaks-width(2.5))),
  width: 10cm,
  height: 6cm,
)

Scatter chart of engine displacement against highway mileage with y axis ticks every 2.5 miles per gallon.

Scatter chart of engine displacement against highway mileage with y axis ticks every 2.5 miles per gallon.

See also

breaks-pretty, breaks-quantile, scale-continuous.

Back to top