Debian Codegraph @

man/desaturate.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/desaturate.R
3 \name{desaturate}
4 \alias{desaturate}
5 \title{Desaturate Colors by Chroma Removal in HCL Space}
6 \usage{
7 desaturate(col, amount = 1, ...)
8 }
9 \arguments{
10 \item{col}{vector of R colors. Can be any of the three kinds of R colors,
11 i.e., either a color name (an element of \code{\link[grDevices]{colors}}), a hexadecimal (hex)
12 string of the form \code{"#rrggbb"} or \code{"#rrggbbaa"} (see
13 \code{\link[grDevices]{rgb}}), or an integer \code{i} meaning
14 \code{palette()[i]}. Additionally, \code{col} can be
15 a formal \code{\link[colorspace]{color-class}} object or a matrix with three named
16 rows (or columns) containing R/G/B (0-255) values.}
17
18 \item{amount}{numeric specifying the amount of desaturation where \code{1}
19 corresponds to complete desaturation, \code{0} to no desaturation, and
20 values in between to partial desaturation.}
21
22 \item{...}{additional arguments. If \code{severity} is specified it will
23 overrule the input argument \code{amount} (for convenience).}
24 }
25 \value{
26 A color object as specified in the input \code{col} (hexadecimal string, RGB matrix,
27 or formal color class) with desaturated colors.
28 }
29 \description{
30 Transform a vector of given colors to the corresponding colors with chroma
31 reduced (by a tunable amount) in HCL space.
32 }
33 \details{
34 If input \code{col} is a vector given colors are first transformed to RGB
35 (either using \code{\link[colorspace]{hex2RGB}} or
36 \code{\link[grDevices]{col2rgb}}) and then to HCL
37 (\code{\link[colorspace]{polarLUV}}). In HCL, chroma is reduced
38 and then the color is transformed back to a hexadecimal
39 string.
40
41 If input \code{col} is a matrix with three rows named \code{R}, \code{G}, and
42 \code{B} (top down) they are interpreted as Red-Green-Blue values within the
43 range \code{[0-255]}. The desaturation takes place in the HCL space as well.
44 Instead of an (s)RGB color vector a matrix of the same size as the input
45 \code{col} with desaturated Red-Green-Blue values will be returned.
46 This can be handy to avoid too many conversions.
47
48 Similarly, \code{col} can be a formal \code{\link[colorspace]{color-class}} object, in which
49 case the desaturated colors are returned as a formal object of the same class as the input.
50 }
51 \examples{
52 ## rainbow of colors and their desaturated counterparts
53 rainbow_hcl(12)
54 desaturate(rainbow_hcl(12))
55
56 ## convenience demo function
57 wheel <- function(col, radius = 1, ...)
58 pie(rep(1, length(col)), col = col, radius = radius, ...)
59
60 ## compare base and colorspace palettes
61 ## (in color and desaturated)
62 par(mar = rep(0, 4), mfrow = c(2, 2))
63 ## rainbow color wheel
64 wheel(rainbow_hcl(12))
65 wheel(rainbow(12))
66 wheel(desaturate(rainbow_hcl(12)))
67 wheel(desaturate(rainbow(12)))
68
69 ## apply desaturation directly on wide RGB matrix (with R/G/B channels in rows)
70 RGB <- diag(3) * 255
71 rownames(RGB) <- c("R", "G", "B")
72 desaturate(RGB)
73 }
74 \references{
75 Zeileis A, Fisher JC, Hornik K, Ihaka R, McWhite CD, Murrell P, Stauffer R, Wilke CO (2020).
76 \dQuote{colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.}
77 \emph{Journal of Statistical Software}, \bold{96}(1), 1--49. \doi{10.18637/jss.v096.i01}
78 }
79 \seealso{
80 \code{\link[colorspace]{polarLUV}}, \code{\link[colorspace]{hex}}, \code{\link[colorspace]{lighten}}
81 }
82 \keyword{color}