pal_ramp | R Documentation |
Interpolate the set of colours in palettes_palette
or
palettes_colour
objects to create new colour palettes.
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")
)
palette |
An object of class |
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: |
interpolate |
The interpolation method. Either "linear" (default) or "spline". |
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.
pal_colour()
, pal_palette()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.