knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of paleval is to help you evaluate the effectiveness of color palettes and color maps. It builds from the colorspace package, used to design color maps, and the farver package, used to evaluate the perceptual difference between two colors.
This will have to go into a design-document eventually, but for now, I'll "puke" this here.
For the purpose of this package, following colorRamp
and ggplot2 usage, we define some classes:
pev_fcont
: A function that describes a continuous palette. When called with a numeric vector with values between 0 and 1, it returns a vector of the corresponding (hex-code) values.
pev_fdisc
: A function that describes a discrete palette. When called with a single integer argument (the number of levels in the scale), it returns a vector of the (hex-code) value for the entire scale. There are two types of discrete-palette functions:
pev_bounded
: Indicates that there is an upper-bound on the number of colors it can provide, e.g. Tableau 10. You would not think to interpolate between these colors.
pev_unbounded
: Indicates that there is no upper-bound on the number of colors it can provide, e.g. "Pastel"
. You might think to interpolate between these colors.
These follow the palette
argument for ggplot2::continuous_scale()
and ggplot2::discrete_scale()
, as well as graphics::colorRamp()
and graphics::colorRampPalette()
, respectively.
I'm suspect I'm doing things in a way that the authors of colorspace
, ggplot2
, farver
, and graphics
might prefer not to consider while eating. As much as anything, this package is an attempt to reationalize and harmonize all of these concepts to myself.
There are ways to create continuous-palette functions:
pev_fcont()
: constructor
pev_fcont
(no-op).pev_fcont_cvd()
: modifies the output of the palette function according to color-vision deficiency.
pev_fcont_diverging()
: composes two continuous-palette functions to create (presumably) a diverging palette-function.
It's up to you to make sure the constituent palettes "meet in the middle". pev_fcont_rescale()
: rescaling an existing continuous-palette function. It may make sense to "zoom-in", but "zooming-out" could get you into trouble. pev_fcont_reverse()
: reverses the sense of the palette function.There are ways to create discrete-palette functions:
pev_fdisc()
: constructor pev_fcont
, given a discretization method
(e.g. "panel"
or "post"
), returns an unbounded function.takes a pev_fdisc
(no-op).
pev_fdisc_cvd()
: modifies the output of the palette function according to color-vision deficiency.
pev_fdisc_reverse()
: reverses the sense of the palette function.
print()
: prints a representation of the palette function.
Other functions:
pev_nmax()
: get the maximum length supported by a discrete-palette function
pev_hex_distance()
: given two (sets of) hex-colors, hex
, hex_ref
:
distance
between them pev_data_separation()
: assess color-separation, given a discrete-palette function,
data.frame
with cvd
, i
, hex
, hex_ref
, distance
pev_gg_separation()
pev_data_derivative()
: assess perceptual-derivative, given a continuous-palette function,
data.frame
with cvd
, x
, hex
, d_distance_d_x
pev_gg_derivative()
pev_data_distance()
: assess perceptual-distance from a reference-color, given a continuous-palette function,
data.frame
with cvd
, x
, hex
, hex_ref
, distance
pev_gg_distance()
pev_data_hcl()
: given hex
, return cvd
, x
, hex
, hue
, chroma
, luminance
, is_boundary
pev_data_hcl_ref()
: given fpal
, hex_ref
, return cvd
, x_nearest
, distance_nearest
, hex
, chroma
, luminance
pev_gg_hcl_bloom()
: given data_hcl
, data_hcl_ref
pev_gg_hcl_plane()
: given data_hcl
, data_hcl_ref
pev_gg_hcl_spectrum()
: given data_hcl
, data_hcl_ref
Here's a reference on delta E - can we find something more definitive?
You can install the development version of paleval from GitHub with:
devtools::install_github("ijlyttle/paleval")
library("paleval") fcont <- pev_fcont("Dynamic") # continuous palette-function, from colorspace fdisc <- pev_fdisc(fcont, method = "panel") # discrete palette-function data_sep <- pev_data_separation(fdisc(7)) print(data_sep) pev_gg_separation(data_sep)
data_drv <- pev_data_derivative("Purple-Green") data_drv pev_gg_derivative(data_drv)
data_dist <- pev_data_distance("Purple-Green") data_dist pev_gg_distance(data_dist)
data_hcl <- pev_data_hcl("Viridis", n = 41) data_hcl data_hcl_ref <- pev_data_hcl_ref("Viridis", pev_fcont("Viridis")(0.55)) pev_gg_hcl_bloom(data_hcl, data_hcl_ref)
pev_data_hcl("Dynamic", n = 12) %>% pev_gg_hcl_bloom()
pev_gg_hcl_plane(data_hcl, data_hcl_ref) pev_gg_hcl_spectrum(data_hcl, data_hcl_ref)
Please note that the 'paleval' project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.