hsl: HSL color specification

View source: R/parse_hsl.R

hslR Documentation

HSL color specification

Description

Create a vector of colors from hue, saturation, and lightness.

Usage

hsl(h = 0, s = 0.5, l = 0.5)

Arguments

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 hue).

s

saturation, number [0,1]; 0 is grey, 1 is full color.

l

lightness, number in [0,1]; 0 is darkest, 1 is brightest.

Details

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 HSL color model tentatively separates color (hue), color intensity (saturation), and color lightness, which helps with the creation of color palettes compared to RGB. However, while the color components are separated numerically, some confusion remains in the way colors are perceived by the human eye/brain. Indeed, even at constant s and l some hues are perceived as brighter (yellow and green for example) and therefore draw the viewer's attention. This is one of the common problems with 'rainbow'-like color scales (which are constructed in HSL or HSV space). See the function luminance for a numerical demonstration. For the creation of color palettes, the HCL space (function hcl) should be preferred.

Value

A vector of colors specified as hex codes

See Also

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(), hsv(), lab(), parse_color(), rgb(), ryb(), temperature(), wavelength()

Examples

hsl()
hsl(330, 1, 0.6)
hsl(data.frame(c(330, 340), c(1,1), c(0.6, 0.4)))
hsl(matrix(c(330, 340, 1, 1, 0.6, 0.4), ncol=3))
hsl(c(330, 340), 1, 0.6)

# Color ramps
ramp <- seq(0, 1, length.out=10)
show_col(hsl(h=ramp*360), hsl(s=ramp), hsl(l=ramp))

jiho/chroma documentation built on Nov. 26, 2022, 2:39 a.m.