Learn R Programming

⚠️There's a newer version (0.2.2) of this package.Take me there.

palettes

palettes is an R package for working with colour vectors and colour palettes. There are three main goals to the palettes package, each described in a vignette:

  • To provide a new family of colour classes (palettes_colour and palettes_palette) that always print as hex codes with colour previews; vignette("palettes").

  • To provide a comprehensive library of methods for working with colour vectors and colour palettes, including methods for ggplot2, vignette("ggplot2"); gt, vignette("gt"); biscale, vignette("biscale"); and other colour packages, vignette("compatibility").

  • To make it easy for anyone to make their own colour palette package; vignette("creating-packages"). Colour palette packages made with palettes exist solely for the purpose of distributing colour palettes and get access to all the features of palettes for free.

Installation

Install palettes from CRAN with:

install.packages("palettes")

Install the development version from GitHub or R-universe with:

# Install from GitHub
# install.packages("remotes")
remotes::install_github("mccarthy-m-g/palettes")

# Install from R-universe
install.packages("palettes", repos = "https://mccarthy-m-g.r-universe.dev")

Install the WebAssembly version for use in WebR applications with:

# Install CRAN version from r-wasm
install.packages("palettes", repos = "https://repo.r-wasm.org")

# Install development version from R-universe
install.packages(
  "palettes",
  repos = c("https://mccarthy-m-g.r-universe.dev", "https://repo.r-wasm.org")
)

Usage

library(palettes)

Colours can be specified by name (as listed by grDevices::colours()):

pal_colour("red")

Or by hex code:

pal_colour("#FF0000")

Multiple colours can be specified at once as a character vector:

pal_colour(c("#a00e00", "#d04e00", "#f6c200", "#0086a8", "#132b69"))

Named colour palettes can be specified in the same way:

pal_palette(
  egypt = c("#dd5129", "#0f7ba2", "#43b284", "#fab255"),
  java  = c("#663171", "#cf3a36", "#ea7428", "#e2998a", "#0c7156")
)

Colours also print nicely in tibbles:

as_tibble(pal_colour(c("#dd5129", "#0f7ba2", "#43b284", "#fab255")))

Documentation

See at https://mccarthy-m-g.github.io/palettes/ and also in the installed package: help(package = "palettes").

License

MIT © Michael McCarthy

Copy Link

Version

Install

install.packages('palettes')

Monthly Downloads

314

Version

0.2.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Michael McCarthy

Last Published

July 13th, 2024

Functions in palettes (0.2.1)

palettes-package

palettes: Methods for Colour Vectors and Colour Palettes
palettes-options

Package options
scale_colour_palette_d

Colour scales from colour vectors and colour palettes
list_colour_symbols

Symbols to use in colour previews
pal_colour

Colour vectors
colour-mixing-arithmetic

Mix colour vectors with arithmetic operators
pal_palette

Colour palettes
pal_ramp

Colour vector and colour palette interpolation
as_tibble.palettes_colour

Cast colour vectors and colour palettes to tibbles
nord_palettes

Nord palettes
pal_numeric

Colour vector and colour palette mapping
colour-mixing-math

Mix colour vectors with math functions
plot.palettes_colour

Plot colour vectors and colour palettes
met_palettes

Metropolitan Museum of Art palettes
viridis_palettes

Viridis palettes
palettes-vctrs

Internal vctrs methods
reexports

Objects exported from other packages
pnw_palettes

Pacific Northwest palettes
palettes-rlang

Internal rlang methods