wavelength: Color specification as wavelength

View source: R/parse_wavelength.R

wavelengthR Documentation

Color specification as wavelength

Description

Convert colors specified as the wavelength of a beam of monochromatic light into an R color.

Usage

wavelength(x)

wl(x)

Arguments

x

vector of wavelengths.

Details

The human eye can distinguish colors between approximately 380 and 750 nm. The colors that we name (arbitrarily, since they really change continuously along the spectrum) are: Violet = [380,450] nm, Blue = [450,495] nm, Green = [495,570] nm, Yellow = [570,590] nm, Orange = [590,620] nm, Red = [620,750] nm.

The correspondance with colors in sRGB-space (the ones R can use) is only approximate because not all monochromatic light colors can be accurately represented in sRGB. Technically it is done by interpolating from a lookup table, described in visible, which itself is a numerical approximation of the match between input colours and sRGB equivalents.

Value

A vector of colors specified as hex codes

See Also

Other color specifications: cmyk(), css(), hcl(), hex(), hsi(), hsl(), hsv(), lab(), parse_color(), rgb(), ryb(), temperature()

Examples

# Display the full visible spectrum
x <- seq(370, 760, length.out=200)
plot(x=x, y=rep(0, 200), col=wavelength(x), pch="|", cex=5)
abline(v=c(380, 450, 495, 570, 590, 620, 750), lty="dotted")

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