Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/christopherkenny/palette

Color Scheme Helpers
https://github.com/christopherkenny/palette

Last synced: 11 days ago
JSON representation

Color Scheme Helpers

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = '#>',
fig.path = 'man/figures/README-',
out.width = '100%'
)
```

# palette

[![CRAN
status](https://www.r-pkg.org/badges/version/palette)](https://CRAN.R-project.org/package=palette)
[![R-CMD-check](https://github.com/christopherkenny/palette/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/christopherkenny/palette/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![palette status badge](https://christopherkenny.r-universe.dev/badges/palette)](https://christopherkenny.r-universe.dev/palette)
[![Codecov test
coverage](https://codecov.io/gh/christopherkenny/palette/branch/main/graph/badge.svg)](https://app.codecov.io/gh/christopherkenny/palette?branch=main)

`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`](https://vctrs.r-lib.org/index.html).
We then provide methods for this class, including `print()`, `plot()`, and [`pillar`](https://pillar.r-lib.org/).
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](https://github.com/) with:

``` r
# 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.

```{r print, results = 'hide'}
library(palette)
palette(roygbiv)
```








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

```{r plot}
plot(palette(roygbiv))
```

For use within `tibble`s, there is a `pillar_shaft` method:

```{r pillar, eval = FALSE}
tibble::tibble(
color = palette(roygbiv)
)
```