pal_ramp: Colour vector and colour palette interpolation

View source: R/pal_ramp.R

pal_rampR Documentation

Colour vector and colour palette interpolation

Description

Interpolate the set of colours in palettes_palette or palettes_colour objects to create new colour palettes.

Usage

pal_ramp(
  palette,
  n = NULL,
  direction = 1,
  space = "lab",
  interpolate = c("linear", "spline")
)

## S3 method for class 'palettes_colour'
pal_ramp(
  palette,
  n = NULL,
  direction = 1,
  space = "lab",
  interpolate = c("linear", "spline")
)

## S3 method for class 'palettes_palette'
pal_ramp(
  palette,
  n = NULL,
  direction = 1,
  space = "lab",
  interpolate = c("linear", "spline")
)

Arguments

palette

An object of class palettes_palette or palettes_colour.

n

An integer specifying the number of colours to return.

direction

Sets the order of colours in the scale. If 1, the default, colours are ordered from first to last. If -1, the order of colours is reversed.

space

The colour space to interpolate in. One of: "cmy", "hsl", "hsb", "hsv", "lab" (CIE L*ab), "hunterlab" (Hunter Lab), "oklab", "lch" (CIE Lch(ab) / polarLAB), "luv", "rgb" (sRGB), "xyz", "yxy" (CIE xyY), "hcl" (CIE Lch(uv) / polarLuv), or "oklch" (Polar form of oklab).

interpolate

The interpolation method. Either "linear" (default) or "spline".

Value

An object of the same type as palette. The output has the following properties:

  • For objects of class palettes_colour: A colour vector with n colours.

  • For objects of class palettes_palette: Colour palettes with n colours in each palette.

See Also

pal_colour(), pal_palette()

Examples

# The class returned after interpolation matches the input class.
x <- pal_colour(c("darkslateblue", "cornflowerblue", "slategray1"))
y <- pal_palette(blues = x)
class(pal_ramp(x))
class(pal_ramp(y))

# Choose between linear and spline interpolation.
pal_ramp(x, n = 7, interpolate = "linear")
pal_ramp(x, n = 7, interpolate = "spline")

# Palettes will have the same length after interpolation, regardless of the
# number of colours in the original palette.
z <- pal_palette(
  Egypt = c("#DD5129", "#0F7BA2", "#43B284", "#FAB255"),
  Java  = c("#663171", "#CF3A36", "#EA7428", "#E2998A", "#0C7156")
)
pal_ramp(z, n = 5)

palettes documentation built on Sept. 11, 2024, 5:57 p.m.