util_make_palette: Format a JavaScript Color Palette

View source: R/util_make_palette.R

util_make_paletteR Documentation

Format a JavaScript Color Palette

Description

Make a specially-formatted color palette based on color codes.

Usage

util_make_palette(colors, continuous = length(colors) < 5,
  divergent = length(colors) > 2, polynomial = FALSE, degrees = 6,
  pad = 10, name = "custom", preview = TRUE, print = TRUE)

Arguments

colors

A vector of color names or HEX codes, or a matrix-like object with colors in columns, and their RGB values in separate rows.

continuous

Logical; if TRUE, colors are treated as points in a linear gradient. One provided color will be from white to that color. Two provided colors will be between those colors. Three or four provided colors will be between the first and last color, with the central color (or average of the central colors) as the midpoint.

divergent

Logical; if TRUE, marks continuous scales as divergent, which will reverse the lower half of the scale.

polynomial

Logical; if TRUE, will fit a polynomial regression model to each color channel in the specified colors sequence. Used to either compress a long sequence (e.g., model a fully manually specified scale), or interpolate a scale between anchors.

degrees

Number of polynomial degrees, if polynomial is TRUE.

pad

If polynomial is TRUE, number of repeated observations of the initial and final colors in the sequence to add in order to reduce warping at the edges.

name

Name of the palette.

preview

Logical; if TRUE, makes a plot showing the palette colors / scale.

print

Logical; if FALSE, will not print a version of the palette.

Value

An invisible list of the created palette.

Examples

# a discrete palette
util_make_palette(c("red", "green", "blue"), FALSE)

# a continuous palette
util_make_palette("red")

# a divergent continuous palette
util_make_palette(c("red", "green"), divergent = TRUE)

uva-bi-sdad/community documentation built on Oct. 12, 2023, 1:18 p.m.