lab | R Documentation |
Create a vector of colors from lightness and a and b color-opponents.
lab(l = 0.5, a = 0.5, b = 0.5)
l |
lightness, number in |
a, b |
color components, numbers with values 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.
The CIE L*a*b* color space is intended to represent all colors visible by the human eye. It separates a lightness component (l
), which matches the human perception of lightness well, from two color "opponents" (a
and b
). To create color palettes however, the HCL color model (function hcl
) is likely to be more practical and is also intended to match human perception of colors.
In R (and in chroma) colors are represented internally in the sRGB color space. Not all CIE L*a*b* colors are representable in sRGB. When a color is not representable in sRGB, it will be converted to the nearest sRGB color. It is therefore possible for two different lab
specifications to yield the same sRGB hex code.
A vector of colors specified as hex codes
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()
,
hcl()
,
hex()
,
hsi()
,
hsl()
,
hsv()
,
parse_color()
,
rgb()
,
ryb()
,
temperature()
,
wavelength()
lab() lab(0.47, 0.55, 0.3) lab(data.frame(c(0.4, 0.6), c(-1, 1), c(-1, 1))) lab(matrix(c(0.4, 0.6, -1, 1, -1, 1), ncol=3)) lab(0.5, c(-1, 1), c(-1, 1)) # Nice lightness scales show_col(lab(l=seq(0, 1, length.out=10))) # CIE L*a*b* space is larger than R's internal sRGB so different # specifications can yield the same sRGB color lab(0.9, -0.5, -0.5) lab(0.9, -0.6, -0.6) # Represent slices of the color space, projected in R's sRGB space ab <- expand.grid(a=seq(-1, 1, length.out=10), b=seq(-1, 1, length.out=10)) plot(ab$a, ab$b, col=lab(l=0.5, a=ab$a, b=ab$b), pch=15, cex=3, asp=1) plot(ab$a, ab$b, col=lab(l=0.2, a=ab$a, b=ab$b), pch=15, cex=3, asp=1) plot(ab$a, ab$b, col=lab(l=1, a=ab$a, b=ab$b), pch=15, cex=3, asp=1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.