Package 'palette'

Title: 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'.
Authors: Christopher T. Kenny [aut, cre]
Maintainer: Christopher T. Kenny <[email protected]>
License: MIT + file LICENSE
Version: 0.0.3
Built: 2024-11-10 03:44:39 UTC
Source: https://github.com/christopherkenny/palette

Help Index


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)

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: TRUE.

use_ggplot

Should the plot be made with ggplot2 if available? Default: TRUE.

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, ...)

desaturate(x, amount = 0.1, ...)

## Default S3 method:
saturate(x, amount = 0.1, ...)

## S3 method for class 'palette'
saturate(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))