Learn R Programming

prismatic

The goal of prismatic is to provide color manipulation tools in R, in a intuitive, low-dependency and functional way.

  • intuitive All the working functions are prefixed with clr_ (color) allowing for easy autocompletion.
  • low-dependency Only depends on farver.
  • functional All functions have consistent inputs and outputs and are thus fully pipeable.

Installation

You can install the released version of prismatic from CRAN with:

install.packages("prismatic")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("EmilHvitfeldt/prismatic")

Examples

All prismatic functions returns a colors object, which includes a new printing method and plotting method for quickly visualizing the colors.

library(prismatic)
library(magrittr)

terrain10 <- terrain.colors(10)

terrain10
#>  [1] "#00A600" "#2DB600" "#63C600" "#A0D600" "#E6E600" "#E8C32E" "#EBB25E"
#>  [8] "#EDB48E" "#F0C9C0" "#F2F2F2"

terrain_color <- color(terrain10)

terrain_color
#> <colors>
#> #00A600FF #2DB600FF #63C600FF #A0D600FF #E6E600FF #E8C32EFF #EBB25EFF #EDB48EFF #F0C9C0FF #F2F2F2FF

plot(terrain_color)

If cli is available the print method will do its best to represent the colors.

library(prismatic)
library(magrittr)
ddd <- color(terrain.colors(10))

ddd
#> <colors>
#> #00A600FF #2DB600FF #63C600FF #A0D600FF #E6E600FF #E8C32EFF #EBB25EFF #EDB48EFF #F0C9C0FF #F2F2F2FF

plot(ddd)
clr_grayscale(ddd) %>% plot()
clr_lighten(ddd, 0.7) %>% plot()
clr_darken(ddd, 0.5) %>% plot()
clr_saturate(ddd, 0.5) %>% plot()
clr_desaturate(ddd, 0.5) %>% plot()
clr_negate(ddd) %>% plot()
clr_rotate(ddd, 180) %>% plot()

clr_protan(ddd) %>% plot()
clr_tritan(ddd) %>% plot()
clr_deutan(ddd) %>% plot()

Related work

This package is hugely inspired by the JavaScript library Qix-/color.

Code of Conduct

Please note that the ‘prismatic’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('prismatic')

Monthly Downloads

182,097

Version

1.1.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

April 10th, 2024

Functions in prismatic (1.1.2)

clr_extract_chroma

Extract HCL components
clr_extract_red

Extract RGB components
prismatic-package

prismatic: Color Manipulation Tools
clr_saturate

Make a color more saturated
best_contrast

Find highest contrast color
clr_alpha

Sets alpha in color
clr_lighten

Make a color more light
clr_extract

Extract Multiple Components
clr_mix

Mixes a color into
clr_grayscale

Transform colors to greyscale
clr_darken

Make a color more dark
check_color_blindness

Visualize color vision deficiency
clr_negate

Negates colors in RGB space
clr_desaturate

Make a color more desaturated
is_color

Test if the object is a color
color

Turn vector to color vector
contrast_ratio

Contrast Ratio Between Colors
clr_rotate

Rotate the colors around the hue wheel
clr_extract_hue

Extract HSL components
modify_hcl

Modify Individual HCL Axes
clr_protan

Simulate color vision deficiency