R: Color Spectrum Plot

specplot {colorspace} | R Documentation

## Color Spectrum Plot

### Description

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

### Usage

    specplot(x, y = NULL, rgb = FALSE, hcl = TRUE, fix = TRUE,
      cex = 1, type = "l", lwd = 2 * cex, lty = 1, pch = NULL,
      mar = NULL, oma = NULL, main = NULL, legend = TRUE,
      palette = TRUE, plot = TRUE, ...)

### Arguments

`x` | character vector containing color hex codes.
`y` | optional second character vector containing further color hex codes, to be used for comparing two palettes (`x` vs. `y`).
`rgb` | logical or color specification. Should the RGB spectrum be visualized? Can also be a vector of three colors for the legend of 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 legend of 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.
`mar, oma` | numeric or logical. Either numeric vectors of length 4 giving the (outer) margins or a logical indicating whether `mar`/`oma` should be set.
`main` | character. Main title of the plot.
`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?
`...` | currently not used.

### Details

The function `specplot` transforms a given color palette in hex codes into their HCL (`polarLUV`) and/or RGB (`sRGB`) 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 HCL and optionally RGB coordinates are visualized by simple line plots along with the color palette `x` itself.

For comparing two palettes, `specplot(x, y)` can be used which adds lines (dashed, by default) corresponding to the `y` palette HCL/RGB coordinates in the display.

### Value

`specplot` invisibly returns a list with components

`HCL` | a matrix of HCL coordinates,
`RGB` | a matrix of sRGB 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. 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. doi: 10.1175/BAMS-D-13-00155.1

Zeileis A, Fisher JC, Hornik K, Ihaka R, McWhite CD, Murrell P, Stauffer R, Wilke CO (2019). “ccolorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.” arXiv:1903.06490, arXiv.org E-Print Archive. http://arxiv.org/abs/1903.06490

### See Also

`hcl_palettes`, `hclplot`

### Examples

    ## spectrum of the (in)famous RGB rainbow palette (in both RGB and HCL)
    specplot(rainbow(100), rgb = TRUE)

    ## spectrum of HCL-based palettes: qualitative/sequential/diverging
    specplot(qualitative_hcl(100, "Set 2"))
    specplot(sequential_hcl(100, "Blues 2"))
    specplot(diverging_hcl(100, "Blue-Red"))

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

[Package colorspace version 1.4-1 Index]