darken: Change color lightness

View source: R/manip_lightness.R

darkenR Documentation

Change color lightness

Description

Darken or brighten colors.

Usage

darken(x, amount = 1)

darker(x, amount = 1)

brighten(x, amount = 1)

brighter(x, amount = 1)

lighten(x, amount = 1)

lighter(x, amount = 1)

Arguments

x

vector of colors specified as hex strings or named R colors.

amount

numeric amount of change in lightness. Reasonable amounts are 1 to 10. Negative amounts correspond to the opposite operation (darken("red", -1) = brighten("red", 1).)

Details

Colors are converted into L*a*b* space where the L* component is changed. Most colors are (very slightly) affected by the conversion and the change in lightness is therefore not exactly reversible (brightening a darkened color will not get you back to the original one); although, perceptually, the changes should be extremely subtle and only affect very bright colors.

Value

A vector of colors specified as hex codes

See Also

Other color manipulation functions: average(), blend(), channel(), luminance(), mix(), saturate()

Examples

darken("#7BBBFE")
darken(c("coral1", "#850E5D"))
brighten("darkgreen")

show_col(c("hotpink", darken("hotpink"), brighten("hotpink")),
         c("lightskyblue", darken("lightskyblue"), brighten("lightskyblue")))
show_col(c(brighten("salmon3", 2),
           brighten("salmon3"),
           "salmon3",
           darken("salmon3"),
           darken("salmon3", 2)))

# darken() and brighten() are opposite operations, the direction of
# which is set by the sign of `amount`
darken("red", -1)
brighten("red", 1)

# But they are not necessarily exactly reversible when they operate near
# extreme lightness values
col <- "#5EFF15"
(new_col <- brighten(darken(col)))
show_col(c(col, new_col))
# = the two greens are slightly different

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