View source: R/manip_lightness.R
darken | R Documentation |
Darken or brighten colors.
darken(x, amount = 1)
darker(x, amount = 1)
brighten(x, amount = 1)
brighter(x, amount = 1)
lighten(x, amount = 1)
lighter(x, amount = 1)
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 ( |
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.
A vector of colors specified as hex codes
Other color manipulation functions:
average()
,
blend()
,
channel()
,
luminance()
,
mix()
,
saturate()
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.