multiHue: Multi-hue color scales

Description Usage Arguments Details Value Examples

View source: R/multihue.R

Description

multihue(), multihue.diverge() address the problem of creating multi-hue (multi "stop") color scales with perceptually linear lightness gradients and smooth hue and chroma gradients (with no first or second order discontinuities).

Usage

1
2
3
4
5
6
7
multiHue(n = 11, colors = c("#081d58", "#086699", "#08BEC1", "#ffff66"))

multiHue.diverge(n = 11, lcolors = c("#0000d0", "#0479C8", "#08C8C8",
  "#ffff00"), rcolors = c("#ffff00", "#FF9696", "#CD4949", "#800000"),
  continuous = TRUE)

multiHue.constantL(n = 11, h = c(0, -45, -90, -135), c = 50, l = 60)

Arguments

n

Integer. Number of levels in palette (number of bins). Default: n = 11.

colors

Character vector. (Only used with multiHue.) A vector of RGB colors specified as hex color codes.

lcolors

Character vector. (Only used with multiHue.diverge.) A vector of RGB colors specified as hex color codes, defining the left side of a diverging palette.

rcolors

Character vector. (Only used with multiHue.diverge.) A vector of RGB colors specified as hex color codes, defining the right side of a diverging palette.

continuous

Logical. (Default: TRUE) If continuous=TRUE (the default), A divergent palette with no central discontinuity is created by joining lcolors and rcolors. The last color of lcolors and the first color of rcolors must be identical. If continuous=FALSE lcolors and rcolors will be abutted, creating a discontinuity last color of lcolors and the first color of rcolors are not identical. A discontinuous palette will always contain an even number of colors (n will be rounded down to the nearest even number).

h

Numeric vector. (Only used with multiHue.constantL.) Hue angles for color stops.

c

Numeric vector. (Only used with multiHue.constantL.) Chroma value(s) for color stops.

l

Numeric. (Only used with multiHue.constantL.) Brightness value for color stops.

Details

Pallettes produced by multihue(), multihue.diverge() and multihue.constantL() use bezier interpolation in HCL space to produce smooth, transient-free color scales. After interpolation, the scales are stretched to correct any non-linearity in brightness gradient introduced by the presence of intermediate color "stops." The result is a perceptually linear brightness gradient, even when printed in black and white.

The palette is specified by a vector of colors (or two vectors in the case of multihue.diverge). The first and last colors of each vector are endpoints of a color scale, and optional intermediate color "stops" are treated as control points for a bezier curve connecting the endpoints in HCL colorspace. These intermediate color stops are therefore not actually present in the final color palette, but influence it. Colors may defined as hex codes or with hue, chroma and lightness values, as in grDevices::hcl().

These functions are built on top of Gregor Aisch's chroma.js javascript library. The functions access chroma.js javascript functions using the V8 package.

Palette characteristics:

Value

character vector. A vector of RGB colors specified as hex color codes (#RRGGBB).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
p <- multiHue()
colorbar(p)

## Maroon to yellow through salmon and pink
stops <- c('#800000', '#CD4949', '#FF9696','#FFFF00')
colorbar(stops) # display stops
palette <- multiHue(1024,colors=stops)
colorbar(palette) # display palette

## Divergent (default)
p <- multiHue.diverge(1024)
colorbar(p)

## Divergent with discontinuity: left = Blue to Cyan, right = Yellow to Red
leftstops <- c("#3136AA","#3980B0","#00C5C0","#8EFDFD")
colorbar(leftstops)
rightstops <- c("#F3F300","#FF8CB4","#CD4C4C","#8F0000")
colorbar(rightstops)
palette <- multiHue.diverge(1024,leftstops,rightstops,continuous=FALSE)
colorbar(palette)

## Constant Lightness (and chroma) color palette:
## 4 color stops define the bezier curve through HCL space; n=6 colors are output.
multiHue.constantL(n=6, h=c(-180, -105, -45, 0),c=50,l=60)

allopole/datacolor documentation built on May 4, 2019, 6:39 p.m.