Declare the scale for the color or the fill channel. Continuous data get a
perceptual ramp; discrete data get a qualitative palette. scale_*_manual()
sets exact colours, scale_*_gradient() a two-point ramp, and
scale_*_gradient2() a diverging three-point ramp (low–mid–high)
centred on midpoint — for signed or anomaly data where a meaningful zero
should sit at the neutral colour. The fill variants set the fill scale the
same way: color and fill are separate scales with separate legends, as in
ggplot2, drawn as one legend when they show the same title and keys. A
legend is drawn automatically when colour or fill is mapped.
Usage
scale_color_continuous(
plot,
palette = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
name = NULL,
oob = NULL
)
scale_color_discrete(
plot,
palette = NULL,
breaks = NULL,
labels = NULL,
name = NULL,
drop = TRUE
)
scale_color_manual(
plot,
values,
name = NULL,
breaks = NULL,
labels = NULL,
limits = NULL,
na.value = NULL,
drop = TRUE
)
scale_color_gradient(
plot,
low = "#132B43",
high = "#56B1F7",
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_color_gradient2(
plot,
low = "#832424",
mid = "#FFFFFF",
high = "#3A3A98",
midpoint = 0,
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_fill_continuous(
plot,
palette = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
name = NULL,
oob = NULL
)
scale_color_gradientn(
plot,
colours,
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_fill_gradientn(
plot,
colours,
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_colour_gradientn(
plot,
colours,
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_fill_discrete(
plot,
palette = NULL,
breaks = NULL,
labels = NULL,
name = NULL,
drop = TRUE
)
scale_fill_manual(
plot,
values,
name = NULL,
breaks = NULL,
labels = NULL,
limits = NULL,
na.value = NULL,
drop = TRUE
)
scale_fill_gradient(
plot,
low = "#132B43",
high = "#56B1F7",
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_fill_gradient2(
plot,
low = "#832424",
mid = "#FFFFFF",
high = "#3A3A98",
midpoint = 0,
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_colour_continuous(
plot,
palette = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
name = NULL,
oob = NULL
)
scale_colour_discrete(
plot,
palette = NULL,
breaks = NULL,
labels = NULL,
name = NULL,
drop = TRUE
)
scale_colour_manual(
plot,
values,
name = NULL,
breaks = NULL,
labels = NULL,
limits = NULL,
na.value = NULL,
drop = TRUE
)
scale_colour_gradient(
plot,
low = "#132B43",
high = "#56B1F7",
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)
scale_colour_gradient2(
plot,
low = "#832424",
mid = "#FFFFFF",
high = "#3A3A98",
midpoint = 0,
name = NULL,
limits = NULL,
breaks = NULL,
labels = NULL,
na.value = NULL,
oob = NULL
)Arguments
- plot
A PlotSpec.
- palette
A vector of colours, or a single palette name passed to
grDevices::hcl.colors()(e.g."Batlow","Blues","Set 2"; matched case/space-insensitively).NULLuses a sensible default.- limits
For the continuous colour scales (including the gradient ones), a length-2 numeric
c(min, max)fixing the mapped data range (the direct form oflims(color = ...)). Forscale_*_manual(), the levels the scale covers.- breaks, labels
Explicit legend breaks / labels, or
NULL.- name
Legend title, or
NULLto derive from the encoding.- oob
For the continuous scales (
scale_*_continuous(),_gradient(),_gradient2(),_gradientn()), what to do with values outsidelimits:"censor"gives them the NA colour,"squish"the colour of the nearest limit,"keep"the same (a ramp cannot extend past its ends), or afunction(x, range).NULL(default) squishes.- drop
For the discrete scales, drop factor levels that no row uses (default
TRUE, as in ggplot2): they get no legend key and no palette entry, so the colours go to the levels that remain.FALSEkeeps every level.limitsoverrides it.- values
For
scale_*_manual(), a vector of colours; if named, matched to data levels by name (unmatched levels draw grey).- na.value
For the gradient scales, the colour of missing (and censored) values; for
scale_*_manual(), also of levels outsidelimits.NULLkeeps the default grey.- low, high
For
scale_*_gradient()/scale_*_gradient2(), the endpoint colours.- mid
For
scale_*_gradient2(), the midpoint colour.- midpoint
For
scale_*_gradient2(), the data value placed atmid(default0); values above and below diverge tohighandlow.- colours
For
scale_*_gradientn(), an n-stop vector of colours the continuous ramp interpolates through.
Value
The modified PlotSpec.
Details
Continuous and binned ramps built from a plain colour vector are interpolated
in the perceptually-uniform Oklab space, so they avoid the muddy, over-dark
midtones and hue drift of sRGB blending. Designed perceptual palettes (the
default, and hcl.colors() names) are already uniform and unaffected. Set
options(vellumplot.color.interpolation = "srgb") (or "lab") to change the
blend space globally.
Examples
vplot(mtcars) |>
mark_point(x = wt, y = mpg, color = hp) |>
scale_color_continuous(palette = "Batlow")
