Color Spectrum Plot

Share:

Description

Visualization of color palettes (given as hex codes) in RGB and/or HCL coordinates.

Usage

1
2
3
  specplot(x, rgb = TRUE, hcl = TRUE, fix = TRUE, cex = 1,
    type = "l", lwd = 2 * cex, lty = 1, pch = NULL,
    legend = TRUE, palette = TRUE, plot = TRUE) 

Arguments

x

character vector containing color hex codes.

rgb

logical or color specification. Should the RGB spectrum be visualized? Can also be a vector of three colors for the R/G/B coordinates.

hcl

logical or color specification. Should the HCL spectrum be visualized? Can also be a vector of three colors for the H/C/L coordinates.

fix

logical. Should the hues be fixed to be on a smooth(er) curve? For details see below.

cex

numeric. Character extension for figure axes and labels.

type, lwd, lty, pch

plotting parameters passed to lines for drawing the RGB and HCL coordinates, respectively. Can be vectors of length 3.

legend

logical. Should legends for the coordinates be plotted?

palette

logical. Should the given palette x be plotted?

plot

logical. Should the RGB and/or HCL coordinates be plotted?

Details

The function specplot transforms a given color palette in hex codes into their RGB (sRGB) or HCL (polarLUV) coordinates. As the hues for low-chroma colors are not (or poorly) identified, by default a smoothing is applied to the hues (fix = TRUE). Also, to avoid jumps from 0 to 360 or vice versa, the hue coordinates are shifted suitably.

By default (plot = TRUE) the resulting RGB and HCL coordinates are visualized by simple line plots along with the color palette x itself.

Value

specplot invisibly returns a list with components

RGB

a matrix of sRGB coordinates,

HCL

a matrix of HCL coordinates,

hex

original color palette x.

Author(s)

Reto Stauffer, Achim Zeileis

References

Zeileis A, Hornik K, Murrell P (2009). Escaping RGBland: Selecting Colors for Statistical Graphics. Computational Statistics & Data Analysis, 53, 3259–3270. \Sexpr[results=rd,stage=build]{tools:::Rd_expr_doi("10.1016/j.csda.2008.11.033")} Preprint available from https://eeecon.uibk.ac.at/~zeileis/papers/Zeileis+Hornik+Murrell-2009.pdf.

Stauffer R, Mayr GJ, Dabernig M, Zeileis A (2015). Somewhere over the Rainbow: How to Make Effective Use of Colors in Meteorological Visualizations. Bulletin of the American Meteorological Society, 96(2), 203–216. \Sexpr[results=rd,stage=build]{tools:::Rd_expr_doi("10.1175/BAMS-D-13-00155.1")}

See Also

rainbow_hcl

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## spectrum of the (in)famous RGB rainbow palette
specplot(rainbow(100))

## spectrum of HCL-based palettes: qualitative/sequential/diverging
specplot(rainbow_hcl(100))
specplot(sequential_hcl(100))
specplot(diverge_hcl(100))

## return computed RGB and HCL coordinates
res <- specplot(rainbow(10), plot = FALSE)
print(res)