Define a scale for an aesthetic channel
Usage
set_scale(
spec,
aesthetic,
type = "auto",
domain = NULL,
range = NULL,
nice = TRUE,
zero = FALSE,
reverse = FALSE,
label = NULL,
format = NULL,
base = NULL
)Arguments
- spec
A glyph_spec
- aesthetic
Which channel: "x", "y", "color", "size", "shape", "alpha"
- type
Scale type: "linear", "log", "sqrt", "time", "ordinal", "band", "quantize", "threshold"
- domain
Explicit domain (data range). NULL for auto. A domain set here is used as given, so it is also how to start the value axis of a bar, area or histogram somewhere other than zero.
- range
Explicit output range. For color: a palette name or vector.
- nice
Round domain to nice values (TRUE/FALSE)
- zero
Force zero in domain (TRUE/FALSE). Bar, area and histogram marks always include zero on their value axis unless
domainis set.- reverse
Reverse the scale
- label
Axis/legend label (NULL for auto from column name)
- format
Format string for tick labels (e.g. "$.2f", "%b %Y")
- base
Log base, used when
type = "log"(default 10 if NULL)
Examples
glyph(mtcars, x = wt, y = mpg) |>
mark_point(color = cyl) |>
set_scale("y", "linear", zero = TRUE, label = "Miles per gallon") |>
set_scale("color", "ordinal", range = "Set2")
#> <glyph_spec: 32 x 11, 1 mark(s)>