vcd (version 1.1-1)

rainbow_hcl: HCL and HSV Color Palettes

Description

Color palettes based on the HCL and HSV color spaces.

Usage

rainbow_hcl(n, c = 50, l = 70, start = 0, end = 360*(n-1)/n, ...)

sequential_hcl(n, h = 260, c. = c(80, 0), l = c(30, 90), power = 1.5, ...) heat_hcl(n, h = c(0, 90), c. = c(100, 30), l = c(50, 90), power = c(1/5, 1), ...) terrain_hcl(n, h = c(130, 0), c. = c(80, 0), l = c(60, 95), power = c(1/10, 1), ...)

diverge_hcl(n, h = c(260, 0), c = 80, l = c(30, 90), power = 1.5, ...) diverge_hsv(n, h = c(2/3, 0), s = 1, v = 1, power = 1, ...)

hcl2hex(h = 0, c = 35, l = 85, gamma = 2.2, fixup = TRUE)

Arguments

n
the number of colors ($\ge 1$) to be in the palette.
c, c.
chroma value in the HCL color description.
l
luminance value in the HCL color description.
start
the hue at which the rainbow begins.
end
the hue at which the rainbow ends.
h
hue value in the HCL or HSV color description, has to be in [0, 360] for HCL and in [0, 1] for HSV colors.
s
saturation value in the HSV color description.
v
value value in the HSV color description.
power
control parameter determining how chroma and luminance should be increased (1 = linear, 2 = quadratic, etc.).
gamma
gamma value of the display.
fixup
logical. Should the color be corrected to a valid RGB value before correction?
...
Other arguments passed to hcl2hex or hsv, respectively.

Value

  • A character vector with RGB codings of the colors in the palette.

encoding

UTF-8

Details

All functions compute palettes based on either the HCL or the HSV color space. For the latter, the implementation hsv from base R is used. The former is implemented in the colorspace package: HCL color space is obtained by taking polar coordinates in CIELUV space which is available via polarLUV from the colorspace package. To transform the HCL coordinates to a hexadecimal color string (as returned by hsv), the function hex is employed. A convenience wrapper hcl2hex is provided. rainbow_hcl computes a rainbow of colors defined by different hues given a single value of each chroma and luminance. It corresponds to rainbow which computes a rainbow in HSV space.

sequential_hcl gives a sequential palette starting at the full color HCL(h, c[1], l[1]) through to a light color HCL(h, c[2], l[2]) by interpolation. diverge_hcl and diverge_hsv, compute a set of colors diverging from a neutral center (grey or white, without color) to two different extreme colors (blue and red by default). This is similar to cm.colors. For the diverging HSV colors, two hues h are needed, a maximal saturation s and a fixed value v. The saturation is then varied to obtain the diverging colors. For the diverging HCL colors, again two hues h are needed, a maximal chroma c and two luminances l. The colors are then created by an interpolation between the full color HCL(h[1], c, l[1]), a neutral color HCL(h, 0, l[2]) and the other full color HCL(h[2], c, l[1]).

The palette heat_hcl gives an implementation of heat.colors in HCL space. By default, it goes from a red to a yellow hue, while simultaneously going to lighter colors (i.e., increasing luminance) and reducing the amount of color (i.e., decreasing chroma). The terrain_hcl palette simply calls heat_hcl with different parameters, providing colors similar in spirit to terrain.colors. The lighter colors are not strictly HCL colors, though.

The diverging palettes are used for choosing the colors for mosaic displays in mosaic.

References

Zeileis A. and Hornik K. (2006), Choosing Color Palettes for Statistical Graphics. Report 41, Department of Statistics and Mathematics, Wirtschaftsuniversität Wien, Research Report Series, http://epub.wu-wien.ac.at/.

See Also

polarLUV, hex, hsv, shadings

Examples

Run this code
## convenience demo functions
wheel <- function(col, radius = 1, ...)
  pie(rep(1, length(col)), col = col, radius = radius, ...) 

pal <- function(col, border = "light gray")
{
  n <- length(col)
  plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab="")
  rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border)
}

## qualitative palette
wheel(rainbow_hcl(12))

## a few useful diverging HCL palettes
par(mar = rep(0, 4), mfrow = c(4, 1))
pal(diverge_hcl(7))
pal(diverge_hcl(7, h = c(246, 40), c = 96, l = c(65, 90)))
pal(diverge_hcl(7, h = c(130, 43), c = 100, l = c(70, 90)))
pal(diverge_hcl(7, h = c(180, 70), c = 70, l = c(90, 95)))
pal(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, 95)))
pal(diverge_hcl(7, h = c(128, 330), c = 98, l = c(65, 90)))
pal(diverge_hcl(7, h = c(255, 330), l = c(40, 90)))
pal(diverge_hcl(7, c = 100, l = c(50, 90), power = 1))

## sequential palettes
pal(sequential_hcl(12))
pal(heat_hcl(12, h = c(0, -100), l = c(75, 40), c = c(40, 80), power = 1))
pal(terrain_hcl(12, c = c(65, 0), l = c(45, 95), power = c(1/3, 1.5)))
pal(heat_hcl(12, c = c(80, 30), l = c(30, 90), power = c(1/5, 1.5)))

## compare base and vcd palettes
par(mfrow = c(2, 1))
wheel(rainbow(12));wheel(rainbow_hcl(12))
pal(diverge_hcl(7, c = 100, l = c(50, 90)));pal(diverge_hsv(7))
pal(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, 95)));pal(cm.colors(7))
pal(heat_hcl(12));pal(heat.colors(12))
pal(terrain_hcl(12));pal(terrain.colors(12))

Run the code above in your browser using DataLab