-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubset_colors.Rd
140 lines (125 loc) · 4.39 KB
/
subset_colors.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colorjam-subset.R
\name{subset_colors}
\alias{subset_colors}
\title{Subset a vector of colors using one or more color attributes}
\usage{
subset_colors(
x,
...,
alpha = TRUE,
byCols = NULL,
return_type = c("colors", "df")
)
}
\arguments{
\item{x}{\code{character} vector of R colors}
\item{...}{any valid criteria to subset the color \code{data.frame}.}
\item{alpha}{\code{logical} indicating whether to retain \code{alpha}
transparency in intermediate operations. When \code{alpha=FALSE} then
all color transparency is ignored, and colors will be returned
with no transparency.}
\item{byCols}{\code{character} vector of colnames to sort after the subset
operation.}
\item{return_type}{\code{character} string to define the return object,
where \code{return_type="colors"} returns a \code{character} vector of colors,
and \code{return_type="df"} returns a \code{data.frame} with the additional
subset colnames included for review.}
}
\value{
\code{character} vector of colors that meet the filter criteria.
When \code{return_type="df"} the returned object is a \code{data.frame} with
the subset columns included for review.
}
\description{
Subset a vector of colors using one or more color attributes
}
\details{
The input colors in \code{x} are converted internally to a \code{data.frame}
with colnames added by relevant helper functions.
\itemize{
\item \code{"num"} contains the integer index of the input vector \code{x}.
\item \code{"hex"} contains \code{character} values with hexadecimal colors
including alpha. If the input \code{x} is \code{"red"} then the hex value
will be converted to \code{"#FF0000FF"}.
}
}
\section{Added by \code{jamba::col2hcl()}}{
\itemize{
\item \code{"H"} contains color hue as values from \code{0} to \code{360}.
\item \code{"C"} contains color chroma (aka saturation) ranging from \code{0} up to \code{200},
where typical "full saturation" is represented as values above 100.
\item \code{"L"} contains color luminance (brightness/lightness) ranging from
\code{0} to \code{100}.
\item \code{"alpha"} the alpha transparency, ranging from \code{0} (fully transparent)
to \code{1} (fully opaque, not transparent).
}
}
\section{Added by \code{grDevices::col2rgb()}}{
\itemize{
\item \code{"red"} contains the red color channel, values range from \code{0} to \code{255}.
\item \code{"green"} contains the green color channel, values range from \code{0} to \code{255}.
\item \code{"blue"} contains the blue color channel, values range from \code{0} to \code{255}.
}
}
\section{Added by \code{jamba::col2hsv()}}{
\itemize{
\item \code{"h"} contains color hue as values from \code{0} to \code{1}. Note these values
may not map directly to color hue obtained from \code{jamba::col2hcl()}.
\item \code{"s"} contains color saturation with values from \code{0} to \code{1}.
\item \code{"v"} contains color vibrance (brightness/lightness) with values
from \code{0} to \code{1}.
}
}
\examples{
# subset for blue colors
jamba::showColors(subset_colors(colors(), H > 200 & H < 265 & C > 80))
# subset for saturated colors
jamba::showColors(subset_colors(colors(), C > 120))
# subset for saturated colors then sort by hue
jamba::showColors(subset_colors(colors(), C > 120, byCols=c("H", "-C", "-L")))
# review the data.frame itself
subset_colors(colors(), C > 135, return_type="df")
# for curiosity, compare H to h
colors_df <- subset_colors(colors(),
C > 20,
byCols=c("C"),
return_type="df");
plot(colors_df$h, colors_df$H,
xlab="hsv hue h",
ylab="HCL hue H",
pch=20,
cex=colors_df$s * 1 + 1,
col=colors_df$hex);
title("Comparison of HCL hue H\nwith hsv hue h")
plot(colors_df$s, colors_df$C,
xlab="hsv saturation s",
ylab="HCL chroma C",
pch=20,
cex=colors_df$s * 1 + 1,
col=colors_df$hex);
title("Comparison of HCL C\nwith hsv s")
plot(colors_df$v, colors_df$L,
xlab="hsv vibrance v",
ylab="HCL luminance L",
pch=20,
cex=colors_df$s * 1 + 1,
col=colors_df$hex);
title("Comparison of HCL L\nwith hsv v")
}
\seealso{
Other colorjam sort:
\code{\link{colors_to_df}()},
\code{\link{sort_colors}()}
Other colorjam core:
\code{\link{blend_colors}()},
\code{\link{closestRcolor}()},
\code{\link{closest_named_color}()},
\code{\link{color_complement}()},
\code{\link{colors_to_df}()},
\code{\link{group2colors}()},
\code{\link{rainbowJam}()},
\code{\link{sort_colors}()}
}
\concept{colorjam core}
\concept{colorjam sort}