Linearly interpolates n colours through the sequence of color, via
grDevices::colorRampPalette(). Unlike palette_manual() (which
interpolates a single curated 5-colour palette), color here is
supplied directly by the caller – any number of colours, in any order.
Usage
palette_gradient(color, n, space = c("Lab", "rgb"))Arguments
- color
A character vector of at least two colours to interpolate through, in order.
- n
A single positive whole number: the number of colours to return.
- space
The colour space interpolation happens in, forwarded to
grDevices::colorRampPalette()'s ownspaceargument:"Lab"(the default) blends perceptually more evenly than"rgb", particularly forcolorpairs far apart in hue.
See also
Other palette helpers:
palette_cosine(),
palette_harmony(),
palette_manual(),
palette_tonal(),
palette_walk()
Examples
palette_gradient(c("midnightblue", "orange"), n = 8)
#> [1] "#191970" "#4D2869" "#703A61" "#8E4D59" "#AA624E" "#C77841" "#E38E2E"
#> [8] "#FFA500"
palette_gradient(c("black", "tomato", "white"), n = 12)
#> [1] "#000000" "#2E1812" "#57281D" "#843829" "#B34934" "#E55A40" "#FF7356"
#> [8] "#FF9076" "#FFAD97" "#FFC8B8" "#FFE3DB" "#FFFFFF"
draw(effect_swatch(color = palette_gradient(c("midnightblue", "orange"), n = 8)))