Learn R Programming

palette

palette provides a lightweight infrastructure for working with color palettes in R. The primary goal is to place colors directly next to their character representations. To do this, we create a palette class based on vctrs. We then provide methods for this class, including print(), plot(), and pillar. To keep it lightweight and usable in other packages, the only direct dependencies are vctrs, cli, and pillar.

Installation

You can install the development version of palette from GitHub with:

# install.packages('pak')
pak::pak('christopherkenny/palette')

Using palette

palette primarily provides a palette vctrs class. Using included data, roygbiv, a length 7 vector of hex codes, we can create a palette.

library(palette)
#> 
#> Attaching package: 'palette'
#> The following object is masked from 'package:grDevices':
#> 
#>     palette
palette(roygbiv)

There is also a plot() method for visualizing the colors:

plot(palette(roygbiv))

For use within tibbles, there is a pillar_shaft method:

tibble::tibble(
  color = palette(roygbiv)
)

Copy Link

Version

Install

install.packages('palette')

Monthly Downloads

243

Version

0.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Last Published

March 15th, 2024

Functions in palette (0.0.2)

palette-vctrs

Internal vctrs methods
palette

Create a palette
palette_browse

Browse a palette on coolors.co
palette_decode_url

Convert a URL to a palette
palette_function

Build a palette function
plot_palette

Plot Palette Colors
vec_ptype2.palette

Palette Coercion
palette-package

palette: Color Scheme Helpers
roygbiv

Rainbow Colors
vec_cast.palette

Palette Casting