color.palette: Create a Custom Interpolated Color Palette

View source: R/color.palette.R

color.paletteR Documentation

Create a Custom Interpolated Color Palette

Description

Constructs a continuous color palette from a sequence of base colors. Intermediate colors are interpolated between each pair of adjacent colors, optionally using a custom number of interpolation steps.

Usage

color.palette(steps, n.steps.between = NULL, ...)

Arguments

steps

A character vector of base colors (e.g., hex codes or color names). These colors define the breakpoints in the palette.

n.steps.between

An optional integer vector specifying how many interpolated colors should be added between each pair of entries in steps. Must have length length(steps) - 1. If NULL (default), no intermediate colors are added beyond the endpoints.

...

Additional arguments passed to methods.

Details

This helper is primarily used for UME visualizations (e.g., color bars in density plots), but it can be used independently for any plotting task.

Value

A function of class "colorRampPalette" that generates interpolated color vectors when called with a single integer argument n.

For example, ⁠pal <- color.palette(c("blue", "white", "red")); pal(100)⁠ returns a vector of 100 smoothly interpolated colors.

Examples

# Generate a simple blue-white-red palette
pal <- color.palette(c("blue", "white", "red"))
pal(10)

# Add additional steps between colors
pal2 <- color.palette(c("blue", "white", "red"), n.steps.between = c(5, 10))
pal2(20)


ume documentation built on Dec. 13, 2025, 1:06 a.m.