Learn R Programming

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

khroma

Overview

Color blindness affects a large number of individuals. When communicating scientific results colour palettes must therefore be carefully chosen to be accessible to all readers.

This R package provides an implementation of Okabe and Ito (2008), Tol (2021) and Crameri (2018) colour schemes. These schemes are ready for each type of data (qualitative, diverging or sequential), with colours that are distinct for all people, including colour-blind readers. This package also provides tools to simulate colour-blindness and to test how well the colours of any palette are identifiable. To simulate colour-blindness in production-ready R figures you may also be interested in the colorblindr package.

Tol (2021) and Crameri (2018) offer carefully chosen schemes, ready for each type of data, with colours that are:

  • Distinct for all people, including colour-blind readers,
  • Distinct from black and white,
  • Distinct on screen and paper,
  • Matching well together,
  • Citable and reproducible.

See vignette("tol") and vignette("crameri") for a more complete overview.

For specific uses, several scientific thematic schemes (geologic timescale, land cover, FAO soils, etc.) are implemented, but these colour schemes may not be colour-blind safe.

All these colour schemes are implemented for use with base R graphics or ggplot2 and ggraph.

Installation

You can install the released version of khroma from CRAN:

install.packages("khroma")

And the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("tesselle/khroma")

Usage

## Load packages
library(khroma)

## Install extra packages (if needed)
# install.packages(c("ggplot2", "spacesXYZ"))
## Get a table of available palettes
info()
#>            palette        type max missing
#> 1             broc   diverging 256    <NA>
#> 2             cork   diverging 256    <NA>
#> 3              vik   diverging 256    <NA>
#> 4           lisbon   diverging 256    <NA>
#> 5           tofino   diverging 256    <NA>
#> 6           berlin   diverging 256    <NA>
#> 7             roma   diverging 256    <NA>
#> 8              bam   diverging 256    <NA>
#> 9           vanimo   diverging 256    <NA>
#> 10          oleron   diverging 256    <NA>
#> 11          bukavu   diverging 256    <NA>
#> 12             fes   diverging 256    <NA>
#> 13           devon  sequential 256    <NA>
#> 14         lajolla  sequential 256    <NA>
#> 15          bamako  sequential 256    <NA>
#> 16           davos  sequential 256    <NA>
#> 17          bilbao  sequential 256    <NA>
#> 18            nuuk  sequential 256    <NA>
#> 19            oslo  sequential 256    <NA>
#> 20           grayC  sequential 256    <NA>
#> 21          hawaii  sequential 256    <NA>
#> 22           lapaz  sequential 256    <NA>
#> 23           tokyo  sequential 256    <NA>
#> 24            buda  sequential 256    <NA>
#> 25           acton  sequential 256    <NA>
#> 26           turku  sequential 256    <NA>
#> 27           imola  sequential 256    <NA>
#> 28          batlow  sequential 256    <NA>
#> 29         batlowW  sequential 256    <NA>
#> 30         batlowK  sequential 256    <NA>
#> 31           brocO  sequential 256    <NA>
#> 32           corkO  sequential 256    <NA>
#> 33            vikO  sequential 256    <NA>
#> 34           romaO  sequential 256    <NA>
#> 35            bamO  sequential 256    <NA>
#> 36          bright qualitative   7    <NA>
#> 37    highcontrast qualitative   3    <NA>
#> 38         vibrant qualitative   7    <NA>
#> 39           muted qualitative   9 #DDDDDD
#> 40  mediumcontrast qualitative   6    <NA>
#> 41            pale qualitative   6    <NA>
#> 42            dark qualitative   6    <NA>
#> 43           light qualitative   9    <NA>
#> 44          sunset   diverging  11 #FFFFFF
#> 45            BuRd   diverging   9 #FFEE99
#> 46            PRGn   diverging   9 #FFEE99
#> 47          YlOrBr  sequential   9 #888888
#> 48      iridescent  sequential  23 #999999
#> 49 discreterainbow  sequential  23 #777777
#> 50   smoothrainbow  sequential  34 #666666
#> 51        okabeito qualitative   8    <NA>
#> 52    stratigraphy qualitative 175    <NA>
#> 53            soil qualitative  24    <NA>
#> 54            land qualitative  14    <NA>

Colour palettes and scales

colour() returns a palette function that when called with a single integer argument returns a vector of colours.

## Paul Tol's bright colour scheme
bright <- colour("bright")
bright(7)
#>      blue       red     green    yellow      cyan    purple      grey 
#> "#4477AA" "#EE6677" "#228833" "#CCBB44" "#66CCEE" "#AA3377" "#BBBBBB" 
#> attr(,"missing")
#> [1] NA
## Show the colour palette
plot_scheme(bright(7), colours = TRUE)
data(mpg, package = "ggplot2")

## Use with graphics
par(mar = c(5, 4, 1, 1) + 0.1)
plot(
  x = mpg$displ,
  y = mpg$hwy,
  pch = 16,
  col = colour("bright")(7)[as.factor(mpg$class)],
  xlab = "displ",
  ylab = "hwy",
  panel.first = grid()
)

## Use with ggplot2
ggplot2::ggplot(data = mpg) +
  ggplot2::aes(x = displ, y = hwy, colour = class) +
  ggplot2::geom_point() +
  ggplot2::theme_bw() +
  scale_colour_bright()

Diagnostic tools

Test how well the colours are identifiable

## Okabe & Ito's colour scheme
okabe <- colour("okabe ito")

set.seed(12345)
plot_map(okabe(8))
## BuRd sequential colour scheme
BuRd <- colour("BuRd")

plot_tiles(BuRd(128), n = 256)

Compute CIELAB distance metric

DeltaE <- compare(okabe(8))
round(DeltaE, 2)
#>                black orange sky blue bluish green yellow  blue vermilion
#> orange         64.74                                                    
#> sky blue       60.95  53.61                                             
#> bluish green   50.51  42.87    34.69                                    
#> yellow         88.42  21.72    57.53        38.04                       
#> blue           39.23  55.35    22.31        38.40  70.37                
#> vermilion      49.36  22.24    52.27        54.36  43.71 49.62          
#> reddish purple 53.11  49.01    45.51        63.45  62.54 41.11     37.02

Simulate colour-blindness

plot_scheme_colourblind(okabe(8))

## ggplot2 default colour scheme
## (equally spaced hues around the colour wheel)
x <- scales::hue_pal()(8)
plot_scheme_colourblind(x)

Contributing

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

References

Crameri, Fabio. 2018. “Geodynamic Diagnostics, Scientific Visualisation and StagLab 3.0.” Geoscientific Model Development 11 (6): 2541–62. https://doi.org/10.5194/gmd-11-2541-2018.

Okabe, Masataka, and Key Ito. 2008. “Color Universal Design (CUD): How to Make Figures and Presentations That Are Friendly to Colorblind People.” J*FLY. https://jfly.uni-koeln.de/color/.

Tol, Paul. 2021. “Colour Schemes.” Technical note SRON/EPS/TN/09-002 3.2. SRON. https://personal.sron.nl/~pault/data/colourschemes.pdf.

Copy Link

Version

Install

install.packages('khroma')

Monthly Downloads

1,332

Version

1.10.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Nicolas Frerebeau

Last Published

April 17th, 2023

Functions in khroma (1.10.0)

scale_crameri_batlowK

Fabio Crameri's batlowK Sequential Colour Scheme
scale_crameri_bukavu

Fabio Crameri's bukavu Multi-Sequential Colour Scheme
scale_crameri_broc

Fabio Crameri's broc Diverging Colour Scheme
scale_crameri_berlin

Fabio Crameri's berlin Diverging Colour Scheme
scale_crameri_buda

Fabio Crameri's buda Sequential Colour Scheme
scale_crameri_bamako

Fabio Crameri's bamako Sequential Colour Scheme
scale_crameri_batlow

Fabio Crameri's batlow Sequential Colour Scheme
scale_crameri_bilbao

Fabio Crameri's bilbao Sequential Colour Scheme
scale_crameri_batlowW

Fabio Crameri's batlowW Sequential Colour Scheme
scale_crameri_brocO

Fabio Crameri's brocO Cyclic Colour Scheme
scale_crameri_grayC

Fabio Crameri's grayC Sequential Colour Scheme
scale_crameri_cork

Fabio Crameri's cork Diverging Colour Scheme
scale_crameri_fes

Fabio Crameri's fes Multi-Sequential Colour Scheme
scale_crameri_imola

Fabio Crameri's imola Sequential Colour Scheme
scale_crameri_cyclic

Fabio Crameri's Cyclic Colour Schemes for ggplot2 and ggraph
scale_crameri_devon

Fabio Crameri's devon Sequential Colour Scheme
scale_crameri_davos

Fabio Crameri's davos Sequential Colour Scheme
scale_crameri_corkO

Fabio Crameri's corkO Cyclic Colour Scheme
scale_crameri_hawaii

Fabio Crameri's hawaii Sequential Colour Scheme
scale_crameri_diverging

Fabio Crameri's Diverging Colour Schemes for ggplot2 and ggraph
scale_crameri_lajolla

Fabio Crameri's lajolla Sequential Colour Scheme
scale_crameri_lapaz

Fabio Crameri's lapaz Sequential Colour Scheme
scale_crameri_romaO

Fabio Crameri's romaO Cyclic Colour Scheme
scale_crameri_oleron

Fabio Crameri's oleron Multi-Sequential Colour Scheme
scale_crameri_nuuk

Fabio Crameri's nuuk Sequential Colour Scheme
scale_crameri_sequential

Fabio Crameri's Sequential Colour Schemes for ggplot2 and ggraph
scale_crameri_lisbon

Fabio Crameri's lisbon Diverging Colour Scheme
scale_crameri_mutlisequential

Fabio Crameri's Multi-Sequential Colour Schemes for ggplot2 and ggraph
scale_crameri_roma

Fabio Crameri's roma Diverging Colour Scheme
scale_crameri_oslo

Fabio Crameri's oslo Sequential Colour Scheme
scale_colour_land

AVHRR Global Land Cover Classification Colour Scheme for ggplot2 and ggraph
scale_crameri_vik

Fabio Crameri's vik Diverging Colour Scheme
scale_crameri_vikO

Fabio Crameri's vikO Cyclic Colour Scheme
scale_logical_discrete

Binary Discrete Colour Schemes for ggplot2 and ggraph
scale_picker

Colour Scale Builder
scale_okabeito_discrete

Okabe and Ito's Discrete Color Scheme for ggplot2 and ggraph
scale_crameri_vanimo

Fabio Crameri's vanimo Diverging Colour Scheme
scale_crameri_turku

Fabio Crameri's turku Sequential Colour Scheme
scale_tol_BuRd

Paul Tol's BuRd Diverging Colour Scheme
scale_tol_PRGn

Paul Tol's PRGn Diverging Colour Scheme
scale_tol_discrete

Paul Tol's Discrete Colour Schemes for ggplot2 and ggraph
scale_crameri_tofino

Fabio Crameri's tofino Diverging Colour Scheme
scale_tol_discreterainbow

Paul Tol's discrete rainbow Sequential Colour Scheme
scale_tol_dark

Paul Tol's dark Discrete Colour Scheme
scale_crameri_tokyo

Fabio Crameri's tokyo Sequential Colour Scheme
scale_tol_diverging

Paul Tol's Diverging Colour Schemes for ggplot2 and ggraph
scale_colour_soil

FAO Soil Reference Groups Color Scheme for ggplot2 and ggraph
scale_colour_stratigraphy

Geologic Timescale Color Scheme for ggplot2 and ggraph
scale_tol_sunset

Paul Tol's sunset Diverging Colour Scheme
scale_tol_vibrant

Paul Tol's vibrant Discrete Colour Scheme
scale_tol_sequential

Paul Tol's Sequential Colour Schemes for ggplot2 and ggraph
scale_tol_smoothrainbow

Paul Tol's smooth rainbow Sequential Colour Scheme
scale_tol_iridescent

Paul Tol's iridescent Sequential Colour Scheme
scale_tol_highcontrast

Paul Tol's high contrast Discrete Colour Scheme
scale_tol_muted

Paul Tol's muted Discrete Colour Scheme
scale_tol_pale

Paul Tol's pale Discrete Colour Scheme
scale_tol_YlOrBr

Paul Tol's YlOrBr Sequential Colour Scheme
scale_tol_light

Paul Tol's light Discrete Colour Scheme
scale_tol_bright

Paul Tol's bright Discrete Colour Scheme
scale_tol_mediumcontrast

Paul Tol's medium contrast Discrete Colour Scheme
convert

Simulate Colour-Blindness
khroma-package

khroma: Colour Schemes for Scientific Data Visualization
scale_crameri_bam

Fabio Crameri's bam Diverging Colour Scheme
plot

Plot Color Scheme
scale_crameri_bamO

Fabio Crameri's bamO Cyclic Colour Scheme
info

Information
scale_crameri_acton

Fabio Crameri's acton Sequential Colour Scheme
ramp

Colour Ramp
compare

Colour Difference
colour

Colour Palette