saturate: Change color saturation

View source: R/manip_saturate.R

saturateR Documentation

Change color saturation

Description

Saturate or desaturate colors

Usage

saturate(x, amount = 1)

desaturate(x, amount = 1)

Arguments

x

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

amount

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

Details

Colors are converted into HCL space where the C (chroma) component is changed. Most colors are (very slightly) affected by the conversion and the change in saturation is therefore not exactly reversible (saturating a desaturated color will not get you back to the original one); although, perceptually, the changes should be extremely subtle and only affect very bright and saturated colors.

Value

A vector of colors specified as hex codes

See Also

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

Examples

saturate("#7BBBFE")
saturate(c("coral1", "#850E5D"))
desaturate("darkgreen")

show_col(c("hotpink", saturate("hotpink"), desaturate("hotpink")),
         c("lightskyblue", saturate("lightskyblue"), desaturate("lightskyblue")))
show_col(c(desaturate("salmon3", 2),
           desaturate("salmon3"),
           "salmon3",
           saturate("salmon3"),
           saturate("salmon3", 2)))

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

# But they are not necessarily exactly reversible when they operate near
# extreme saturation values
col <- "#5EFF15"
(new_col <- desaturate(saturate(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.