show_colors: Show colors

View source: R/plot_extra.R

show_colorsR Documentation

Show colors

Description

R includes 657 named colors. This is a convenience function to locate specific ones quickly.

Find a color by index in the plot created with show_colors() by first locating the desired color and summing the row and column indices corresponding to its position.

Return a color name or index by giving the index or name, respectively, optionally, plotting one or more. Search for all colors with a pattern, such as "red|orange", and return all matches, optionally plotting.

Usage

show_colors(..., plot = FALSE)

Arguments

...

integer(s) in 1:657 corresponding to the built-in color name index or color name string(s); if ? is included as a string or part of a string, color names will be searched for matches

plot

logical; if TRUE, integers or color names in ... will be plotted with corresponding number and name

Value

If ... is missing, a plot will be drawn. If an integer is given, the color name will be returned; if a color name string is given, the index will be returned. For the latter two options, no plot is drawn by default but will be if plot = TRUE. If one or more strings are given and one contains a "?", all color names matching the input will be returned and optionally plotted.

See Also

show_pch; colors; waffle; tcol

Examples

## typical usage
show_colors()
show_colors(5, 6, 544)
show_colors('blue4', 'dodgerblue2')


## search for color names or numbers
show_colors(grep('red|orange', colors()), plot = TRUE)
## shorthand
show_colors('?red', 'orange')
show_colors('?red|orange', plot = TRUE)


## this function is its own inverse
show_colors(81)
show_colors('darkgreen')

x <- show_colors(sample(657, 10))
identical(x, show_colors(show_colors(x)))

## these plots are identical
show_colors(x, plot = TRUE)
show_colors(show_colors(x), plot = TRUE)


raredd/rawr documentation built on April 29, 2024, 10:29 a.m.