hcl | R Documentation |
Create a vector of colors from hue, chromacity, and lightness.
hcl(h = 0, c = 0.65, l = 0.65, alpha = NULL, compat = FALSE, ...) lch(l = 0.65, c = 0.65, h = 0)
h |
hue, either an angle around the color wheel, in [0,360] (angles outside of the range are rotated back to within [0, 360]: 380 = 20, -15 = 345, etc.), or a color (hex or named) from which the hue is extracted (by function |
c |
chromacity, number in |
l |
lightness, number in |
alpha |
transparency, number in |
compat |
whether to make the conventions compatible with the built-in function |
... |
ignored, for compatibility with the built-in |
The first argument can also be a data.frame or a matrix. In that case, its columns are considered as the color components, taken in order, and the other color components arguments are ignored.
When separate arguments are used for the color components and are vectors, values in shorter arguments are recycled to match the length of the longest argument. If the lengths are not compatible, an error is output.
In HCL space, the perceived color (hue) is completely separated from the perceived intensity (chromacity) and lightness of the color. This means that colors of various hues but same chromacity and lightness appear as the exact same grey when converted to greyscale. This makes the HCL space particularly suitable to create good color palettes:
For qualitative palettes (discrete variables): varying h
at constant c
and l
avoids drawing attention to certain hues, as would happen if the same was done in HSV or HSL space. Indeed, some hues are perceived as brighter (yellow, light green, etc.), others as duller/darker (blues, etc.).
For sequential palettes (continuous variables): varying l
(or possibly c
) for a constant h
gives a sense of direction and avoid the many perceptual pitfalls typical of 'rainbow'-like scales.
A vector of colors specified as hex codes
HCL-based color scales: hue_scale
, chroma_scale
, and light_scale
.
parse_color
for the general function to parse colors in various specifications (which this function calls internally) and convert_color
to convert parsed colors to another model.
Other color specifications:
cmyk()
,
css()
,
hex()
,
hsi()
,
hsl()
,
hsv()
,
lab()
,
parse_color()
,
rgb()
,
ryb()
,
temperature()
,
wavelength()
hcl() hcl(330, 1, 0.6) hcl(data.frame(c(330, 340), c(1,1), c(0.6, 0.4))) hcl(matrix(c(330, 340, 1, 1, 0.6, 0.4), ncol=3)) hcl(c(330, 340), 1, 0.6) # Compare "rainbow"-like scales in various color spaces ramp <- seq(0, 1, length.out=10) show_col( hcl(h=ramp*360), hsv(h=ramp*360, s=0.9), hsl(h=ramp*360, s=0.9) ) # Hue, chromacity, and lightness scales show_col( hcl(h=ramp*360), hcl(c=ramp), hcl(l=ramp) ) # Nice color palettes show_col( hcl(h=80+ramp*240, c=0.2+ramp*0.4, l=0.9-ramp*0.6), hcl(h=240-ramp*120, c=0.5, l=ramp*0.9), hcl(h=0+ramp*80, c=0.6-ramp*0.4, l=0.1+ramp*0.8), hcl(h=210+ramp*150, c=0.3, l=0.1+ramp*0.5) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.