Learn R Programming

ume (version 1.5.2)

color.palette: 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, ...)

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.

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab