View source: R/manip_luminance.R
luminance | R Documentation |
Get or set the relative brightness of colors
luminance(x) luminance(x) <- value
x |
vector of colors specified as hex strings or named R colors. |
value |
the luminance value, as a number in [0,1] |
luminance
gets the relative brightness of colors, normalised to 0 for darkest black and 1 for lightest white according to the WCAG definition http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef.
luminance<-
sets the relative brightness by interpolating with black or white until the appropriate relative luminance is found. The changes in luminance are not reversible because the interpolation to black or white changes various aspects of the color simultaneously: its lightness of course but also its intensity and even possibly its hue (at the extreme, black or white have no well-defined hue).
For luminance
, a vector of luminance values, each in [0,1].
For luminance<-
, the updated object(s).
channel
to extract or set a given channel, in particular the lightness channel in HSL, HCL, or L*a*b* color spaces.
Other color manipulation functions:
average()
,
blend()
,
channel()
,
darken()
,
mix()
,
saturate()
luminance("black") luminance("white") luminance("red") # Colors along a HSV rainbow have very different relative brightness luminance(rainbow(6)) # but brightness is much more homogenous along a HCL "rainbow" luminance(hcl(h=seq(0, 360, length.out=6))) # Change the luminance col <- "red" luminance(col) <- 0.5 show_col(c("red", col)) # This can even be used to create color ramps, although the steps in # perceived brightness may not be regular at the extremes col <- "red" luminance(col) <- seq(0, 1, length.out=10) show_col(col) # Better to avoid the extremes then col <- "red" luminance(col) <- seq(0.1, 0.9, length.out=10) show_col(col)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.