colorbar: Display a palette, simulate colorblindness and greyscale,...

Description Usage Arguments Details Examples

View source: R/colorbar.R

Description

colorbar() displays a palette as a horizontal colorbar. colorplot() displays a palette as a horizontal colorbar and plots its Hue (H), Chroma (C) and Lightness (L). HCL is a perceptually uniform colorspace.

Usage

1
2
3

Arguments

palette

Character vector. A palette (vector of hex RGB or RGBA colors).

dots

Logical. If dots=TRUE, a row of circles (dots) will be drawn instead of a colorbar.

colorblind

Logical. If colorblind=TRUE, colorbars (or dots) for three common types of colorblindness (deuteranopia, protanopia and tritanopia) and greyscale will also be displayed.

Details

Both functions can also simulate greyscale printing and three forms of colorblindness.

The input palette must be a character vector of colors as 'hex' RGB or RGBA strings (e.g."#006633" or "#006633FF"), such as produced by most color functions in R.

NA's may occur in a palette if it was produced with grDevices::hcl() using fixup=FALSE. NA's produced by an HCL function are out-of-gamut colors (not possible to display in RGB space). NA's are displayed as white gaps in the colorbar and black verticals in the plots of H, C and L.

Although the HCL colorspace is often used to create perceptually uniform color palettes, these palettes are converted to RGB colorspace for display on screen, which introduces artifacts arising from the conversion from high precision (float) to the 8-bit precision of RGB. Since colorplot() analyzes the palette after it has been converted to RGB for display, it accurately represents the palette as it will be displayed on screen, with any artifacts.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Draw a colorbar or row of dots
pal <- grDevices::rainbow(36)
colorbar(pal)
colorbar(pal,dots=TRUE)
colorbar(pal,colorblind=TRUE)
colorbar(pal,dots=TRUE,colorblind=TRUE)

# plot colobar (or dots) and HCL for the palette
colorplot(pal)
colorplot(pal,dots=TRUE)
colorplot(pal,colorblind=TRUE)
colorplot(pal,dots=TRUE,colorblind=TRUE)

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