scales (version 0.3.0)

colour_ramp: Fast color interpolation

Description

Returns a function that maps the interval [0,1] to a set of colors. Interpolation is performed in the CIELAB color space. Similar to colorRamp(space = 'Lab'), but hundreds of times faster, and provides results in "#RRGGBB" (or "#RRGGBBAA") character form instead of RGB color matrices.

Usage

colour_ramp(colors, na.color = NA, alpha = FALSE)

Arguments

colors
Colors to interpolate; must be a valid argument to col2rgb. This can be a character vector of "#RRGGBB" or "#RRGGBBAA", color names from
na.color
The color to map to NA values (for example, "#606060" for dark grey, or "#00000000" for transparent) and values outside of [0,1]. Can itself by NA, which will simply cause an NA to be insert
alpha
Whether to include alpha channels in interpolation; otherwise, any alpha information will be discarded. If TRUE then the returned function will provide colors in "#RRGGBBAA" format instead of "#RRGGBB".

Value

  • A function that takes a numeric vector and returns a character vector of the same length with RGB or RGBA hex colors.

See Also

colorRamp