grepal | R Documentation |
grepal
returns a vector of colors whose names match a regular expression (regex).
grepal(pattern, x = colors(), ignore_case = TRUE, plot = TRUE)
pattern |
A regular expression (specified as a string/character object). |
x |
A vector of R color names or a data frame of named colors
(i.e., whose names can be searched).
Default: |
ignore_case |
Should the case of pattern be ignored
(passed to |
plot |
Boolean: Plot the output (using |
By default, the base R vector of named colors (i.e., colors()
) is searched
for names matching a pattern
(which can be a simple string or regular expression).
If x
(i.e., the object to be searched) is provided,
it is must be a vector of color names or a data frame of named color objects
(i.e., a color palette).
If plot = TRUE
, grepal
also visualizes the detected colors
(by passing its result to seecol
, as a side-effect).
This function facilitates searching colors by name and
yields (a vector of) colors of similar color hue (provided
that the color's hue is expressed in a color's name).
Its name grepal
is an abbreviation of grep
and "pal".
seecol
for viewing and comparing color palettes;
usecol
for using color palettes;
simcol
for finding similar colors;
newpal
for defining new color palettes;
shades_of
to defining shades of a given color;
ac
for adjusting color transparency;
pal_unikn
for the default uni.kn color palette.
Other color functions:
ac()
,
demopal()
,
newpal()
,
seecol()
,
shades_of()
,
simcol()
,
usecol()
grepal("tan")
# With regular expressions:
some_grey <- grepal("gr(a|e)y", plot = FALSE)
start_grey <- grepal("^gr(a|e)y", plot = FALSE)
only_grey <- grepal("^gr(a|e)y$", plot = FALSE)
length(some_grey)
length(only_grey)
# With other color objects (df as x):
grepal("blau", x = pal_unikn)
grepal("SEE", x = pal_unikn_pref, ignore_case = FALSE)
# Applications:
seecol(grepal("white"), col_bg = "lightblue2", main = "See 'white' colors()")
olives <- grepal("olive", plot = FALSE)
oranges <- grepal("orange", plot = FALSE)
seecol(list(olives, oranges),
pal_names = c("olives", "oranges"),
main = "Comparing olives and oranges")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.