Title: | Color Scheme Helpers |
Version: | 0.0.3 |
Description: | Hexadecimal codes are typically used to represent colors in R. Connecting these codes to their colors requires practice or memorization. 'palette' provides a 'vctrs' class for working with color palettes, including printing and plotting functions. The goal of the class is to place visual representations of color palettes directly on or, at least, next to their corresponding character representations. Palette extensions also are provided for data frames using 'pillar'. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
URL: | https://github.com/christopherkenny/palette, https://christophertkenny.com/palette/ |
BugReports: | https://github.com/christopherkenny/palette/issues |
Imports: | cli, pillar, vctrs |
Suggests: | ggplot2, spelling, testthat (≥ 3.0.0), vdiffr |
Config/testthat/edition: | 3 |
Language: | en-US |
Depends: | R (≥ 4.1.0) |
NeedsCompilation: | no |
Packaged: | 2025-09-12 16:12:04 UTC; chris |
Author: | Christopher T. Kenny
|
Maintainer: | Christopher T. Kenny <ctkenny@proton.me> |
Repository: | CRAN |
Date/Publication: | 2025-09-13 05:10:29 UTC |
palette: Color Scheme Helpers
Description
Hexadecimal codes are typically used to represent colors in R. Connecting these codes to their colors requires practice or memorization. 'palette' provides a 'vctrs' class for working with color palettes, including printing and plotting functions. The goal of the class is to place visual representations of color palettes directly on or, at least, next to their corresponding character representations. Palette extensions also are provided for data frames using 'pillar'.
Author(s)
Maintainer: Christopher T. Kenny ctkenny@proton.me (ORCID)
See Also
Useful links:
Report bugs at https://github.com/christopherkenny/palette/issues
Control palette brightness
Description
Generic function to control the brightness of a palette.
Usage
darken(x, amount = 0.1, ...)
lighten(x, amount = 0.1, ...)
## Default S3 method:
darken(x, amount = 0.1, ...)
## S3 method for class 'palette'
darken(x, amount = 0.1, ...)
## Default S3 method:
lighten(x, amount = 0.1, ...)
## S3 method for class 'palette'
lighten(x, amount = 0.1, ...)
Arguments
x |
A vector of colors |
amount |
A numeric value to control the brightness of the palette |
... |
Additional arguments passed to other methods. Currently ignored. |
Value
A palette vector with the brightness adjusted
Examples
darken(palette(roygbiv))
lighten(palette(roygbiv))
Create a palette
Description
A palette
is a class for color palettes built on vctrs
. It is represented
as a character vector of hexadecimal color codes. Named colors (like 'red'
)
are translated to hexadecimal color codes.
Usage
palette(x = character())
validate_palette(x)
is_palette(x)
as_palette(x)
Arguments
x |
A character vector of colors |
Value
a palette vector
Examples
palette(roygbiv)
Internal vctrs methods
Description
Internal vctrs methods
Browse a palette on coolors.co
Description
Browse a palette on coolors.co
Usage
palette_browse(x)
palette_browse_url(x)
Arguments
x |
A palette |
Value
A URL to the palette
Examples
palette_browse(roygbiv)
Convert a URL to a palette
Description
This function takes a URL from either <coolors.co> or <colorhunt.co> and returns the palette.
Usage
palette_decode_url(x)
Arguments
x |
A URL from either 'coolors.co' or 'colorhunt.co' |
Value
a vector of type palette
Examples
palette_decode_url('https://coolors.co/ff4444-ffae4d-ffff60-50ff50-3939fa')
palette_decode_url('https://www.colorhunt.co/palette/b5c0d0ccd3caf5e8ddeed3d9')
Build a palette function
Description
Creates a palette function for use within ggplot2
as an argument to discrete_scale
.
If the number of colors requested is greater than the length of the palette,
the palette will be repeated. If the number of colors requested is less than the
length of the palette, the palette will be truncated. This is done explicitly, as
vctrs
recycling purposefully does not recycle to partial lengths, like a vector of
size 10 to a vector of size 3 or 13.
Usage
palette_function(x)
Arguments
x |
a palette |
Value
a function which takes an integer n
and returns a vector of n
colors
Examples
palette_function(palette(roygbiv))(10)
Plot Palette Colors
Description
Plot Palette Colors
Usage
plot_palette(x, use_names = TRUE, use_ggplot = TRUE)
Arguments
x |
a palette |
use_names |
Should the names of the palette be used as labels? Default: |
use_ggplot |
Should the plot be made with ggplot2 if available? Default: |
Value
A ggplot
(if ggplot2 is available) or base plot of the palette
Examples
plot_palette(roygbiv)
Rainbow Colors
Description
Rainbow Colors
Usage
roygbiv
Format
character vector of 7 hex codes
Examples
palette(roygbiv)
Control palette saturation
Description
Generic function to control the saturation of a palette.
Usage
saturate(x, amount = 0.1, ...)
## Default S3 method:
saturate(x, amount = 0.1, ...)
## S3 method for class 'palette'
saturate(x, amount = 0.1, ...)
desaturate(x, amount = 0.1, ...)
## Default S3 method:
desaturate(x, amount = 0.1, ...)
## S3 method for class 'palette'
desaturate(x, amount = 0.1, ...)
Arguments
x |
A vector of colors |
amount |
A numeric value to control the saturation of the palette |
... |
Additional arguments passed to other methods. Currently ignored. |
Value
A palette vector with the saturation adjusted
Examples
saturate(palette(roygbiv))
desaturate(palette(roygbiv))
Palette Casting
Description
Dispatch methods for vctrs::vec_cast()
Usage
## S3 method for class 'palette'
vec_cast(x, to, ...)
Arguments
x |
Vectors to cast. |
to |
Type to cast to. If |
... |
For |
Value
a vector of the same length, as class palette
if convertible, otherwise character
Palette Coercion
Description
Coercion methods for vctrs::vec_ptype2()
Usage
## S3 method for class 'palette'
vec_ptype2(x, y, ...)
Arguments
x , y |
Vector types. |
... |
These dots are for future extensions and must be empty. |
Value
a vector of the same length, as class palette
if convertible, otherwise character