colorspace: atoolboxformanipulatingand ... · figure 6: palette visualization and assessment for...

45
colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes Achim Zeileis Universität Innsbruck Jason C. Fisher U.S. Geological Survey Kurt Hornik WU Wirtschafts- universität Wien Ross Ihaka University of Auckland Claire D. McWhite The University of Texas at Austin Paul Murrell University of Auckland Reto Stauffer Universität Innsbruck Claus O. Wilke The University of Texas at Austin Abstract The R package colorspace provides a flexible toolbox for selecting individual colors or color palettes, manipulating these colors, and employing them in statistical graphics and data visualizations. In particular, the package provides a broad range of color palettes based on the HCL (Hue-Chroma-Luminance) color space. The three HCL dimensions have been shown to match those of the human visual system very well, thus facilitating intuitive selection of color palettes through trajectories in this space. Using the HCL color model general strategies for three types of palettes are implemented: (1) Qualitative for coding categorical information, i.e., where no particular ordering of categories is available. (2) Sequential for coding ordered/numeric information, i.e., going from high to low (or vice versa). (3) Diverging for coding ordered/numeric information around a central neu- tral value, i.e., where colors diverge from neutral to two extremes. To aid selection and application of these palettes the package also contains scales for use with ggplot2, shiny (and tcltk) apps for interactive exploration, visualizations of palette properties, accom- panying manipulation utilities (like desaturation and lighten/darken), and emulation of color vision deficiencies. Keywords : color, palette, HCL, RGB, hue, color vision deficiency, R. 1. Introduction Color is an integral and omnipresent element of many statistical graphics and data visual- izations. Therefore, colors should be carefully chosen to support all viewers in accessing the information displayed (Tufte 1990; Brewer 1999; Ware 2004; Wilkinson 2005; Wilke 2019). However, until relatively recently many software packages have been using color palettes derived from simple RGB (red-green-blue) color combinations such as the RGB “rainbow” (or “jet”) color palette with poor perceptual properties. See Hawkins, McNeall, Stephen- son, Williams, and Carlson (2014) and Stauffer, Mayr, Dabernig, and Zeileis (2015) and the references therein for an overview. arXiv:1903.06490v1 [stat.CO] 14 Mar 2019

Upload: others

Post on 24-Jan-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

colorspace: A Toolbox for Manipulating andAssessing Colors and Palettes

Achim ZeileisUniversität Innsbruck

Jason C. FisherU.S. Geological Survey

Kurt HornikWU Wirtschafts-universität Wien

Ross IhakaUniversity of Auckland

Claire D. McWhiteThe University ofTexas at Austin

Paul MurrellUniversity of Auckland

Reto StaufferUniversität Innsbruck

Claus O. WilkeThe University ofTexas at Austin

Abstract

The R package colorspace provides a flexible toolbox for selecting individual colors orcolor palettes, manipulating these colors, and employing them in statistical graphics anddata visualizations. In particular, the package provides a broad range of color palettesbased on the HCL (Hue-Chroma-Luminance) color space. The three HCL dimensionshave been shown to match those of the human visual system very well, thus facilitatingintuitive selection of color palettes through trajectories in this space. Using the HCL colormodel general strategies for three types of palettes are implemented: (1) Qualitative forcoding categorical information, i.e., where no particular ordering of categories is available.(2) Sequential for coding ordered/numeric information, i.e., going from high to low (orvice versa). (3) Diverging for coding ordered/numeric information around a central neu-tral value, i.e., where colors diverge from neutral to two extremes. To aid selection andapplication of these palettes the package also contains scales for use with ggplot2, shiny(and tcltk) apps for interactive exploration, visualizations of palette properties, accom-panying manipulation utilities (like desaturation and lighten/darken), and emulation ofcolor vision deficiencies.

Keywords: color, palette, HCL, RGB, hue, color vision deficiency, R.

1. Introduction

Color is an integral and omnipresent element of many statistical graphics and data visual-izations. Therefore, colors should be carefully chosen to support all viewers in accessing theinformation displayed (Tufte 1990; Brewer 1999; Ware 2004; Wilkinson 2005; Wilke 2019).However, until relatively recently many software packages have been using color palettesderived from simple RGB (red-green-blue) color combinations such as the RGB “rainbow”(or “jet”) color palette with poor perceptual properties. See Hawkins, McNeall, Stephen-son, Williams, and Carlson (2014) and Stauffer, Mayr, Dabernig, and Zeileis (2015) and thereferences therein for an overview.

arX

iv:1

903.

0649

0v1

[st

at.C

O]

14

Mar

201

9

Page 2: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

2 colorspace: Manipulating and Assessing Colors and Palettes

Hue(Type of color)

Chroma(Colorfulness)

Luminance(Brightness)

0

0

95

75

25

75

150

50

55

225

75

35

300

100

15

Figure 1: Axes of the HCL color space. Top: Hue H changes from 0 (red) via 75 (yellow),etc. to 300 (purple) with fixed C = 60 and L = 65. Center: Chroma C changes from 0 (gray)to 100 (colorful) with fixed H = 0 (red) and L = 65. Bottom: Luminance L changes from 95(light) to 15 (dark) with fixed H = 260 (blue) and C = 25 (low, close to gray).

To address these problems, many improved color palettes with better perceptual propertieshave been receiving increasing attention in the literature (Harrower and Brewer 2003; Zeileis,Hornik, and Murrell 2009; Smith and Van der Walt 2015; CARTO 2019; Crameri 2018). Manysystems for systems for statistical and scientific computing provide infrastructure for suchcolor palettes, e.g., for R (R Core Team 2018) the list of useful packages encompasses: RCol-orBrewer (Neuwirth 2014), viridis (Garnier 2018), rcartocolor (Nowosad 2018), wesanderson(Ram and Wickham 2018), or scico (Pedersen and Crameri 2018) among many others. Fur-thermore, packages like pals (Wright 2018) and paletteer (Hvitfeldt 2019) collect many of theproposed palettes in combination with a unified interface. Most of these palettes, however,are pre-existing palettes, stored as a limited set of colors and interpolated as necessary. Andeven if specific algorithms have been used in the initial construction of the palettes, these areoften not reflected in the software implementations.The colorspace package (Ihaka et al. 2019) adopts a somewhat different approach that givesthe user direct access to the construction principles underlying its palettes. These are basedon simple trajectories in the perceptually-based HCL (Hue–Chroma–Luminance) color space(Wikipedia 2019e) whose axes match those of the human visual system very well: Hue (=type of color, dominant wavelength), chroma (= colorfulness), luminance (= brightness), seeFigure 1. Thus, utilizing this color model the colorspace package can derive general andadaptable strategies for color palettes; manipulate individual colors and color palettes; andassess and visualize the properties of color palettes (beyond simple color swatches). Specifi-cally, colorspace provides three types of palettes based on the HCL model:

• Qualitative: Designed for coding categorical information, i.e., where no particular order-ing of categories is available and every color should receive the same perceptual weight.Function: qualitative_hcl().

• Sequential: Designed for coding ordered/numeric information, i.e., where colors go fromhigh to low (or vice versa). Function: sequential_hcl().

• Diverging: Designed for coding ordered/numeric information around a central neutralvalue, i.e., where colors diverge from neutral to two extremes. Function: diverging_hcl().

A broad collection of prespecified palettes are shipped in the package. In addition, existingpalettes can be easily tweaked and new or adapted palettes registered. The prespecified

Page 3: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 3

palettes include suitable HCL color choices that closely approximate of most palettes frompackages RColorBrewer, rcartocolor, and viridis by using only a small set of hue, chroma,and luminance parameters.To aid choice and application of these palettes the package provides (a) scales for use withggplot2 (Wickham 2016), (b) shiny (Chang, Cheng, Allaire, Xie, and McPherson 2018) andtcltk (R Core Team 2018) apps for interactive exploration, (c) visualizations of palette prop-erties, and (d) accompanying manipulation utilities (like desaturation, lighten/darken, andemulation of color vision deficiencies).The remainder of the manuscript is organized as follows: Section 2 gives a first overview of thepackage’s “look & feel” and the general workflow. Section 3 summarizes the S4 color spaceclasses and methods in the package. Section 4 introduces the extensible collection of HCL-based palettes along with their construction details. Section 5 presents the toolbox for palettevisualization and assessment. Section 6 discusses the implemented techniques for color visiondeficiency emulation that help assess the suitability of colors for colorblind viewers. Section 7briefly highlights the interactive color apps from the package. Finally, some further colormanipulation utilities are highlighted in Section 8 before Section 9 concludes the manuscript.

2. A quick tourThe stable release version of colorspace is hosted on the Comprehensive R Archive Network(CRAN) at https://CRAN.R-project.org/package=colorspace and the development ver-sion of colorspace is hosted on R-Forge at https://R-Forge.R-project.org/projects/colorspace/.

2.1. Choosing HCL-based color palettes

The colorspace package ships with a wide range of predefined color palettes, specified throughsuitable trajectories in the HCL (Hue-Chroma-Luminance) color space. A quick overview canbe gained easily with the hcl_palettes() function (see Figure 2):

R> library("colorspace")R> hcl_palettes(plot = TRUE)

A suitable vector of colors can be easily computed by specifying the desired number of colorsand the palette name (see Figure 2 for possible palette names), e.g.,

R> q4 <- qualitative_hcl(4, palette = "Dark 3")R> q4

[1] "#E16A86" "#909800" "#00AD9A" "#9183E6"

The functions sequential_hcl(), and diverging_hcl() work analogously. Additionally,a palette’s hue/chroma/luminance parameters can be modified, thus allowing for easy cus-tomization of each palette. Moreover, the choose_palette()/hclwizard() app providesconvenient user interfaces to perform palette customization interactively. Finally, even moreflexible diverging HCL palettes are provided by divergingx_hcl().

Page 4: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

4 colorspace: Manipulating and Assessing Colors and Palettes

Qualitative

Pastel 1

Dark 2

Dark 3

Set 2

Set 3

Warm

Cold

Harmonic

Dynamic

Sequential (single−hue)

Grays

Light Grays

Blues 2

Blues 3

Purples 2

Purples 3

Reds 2

Reds 3

Greens 2

Greens 3

Oslo

Sequential (multi−hue)

Purple−Blue

Red−Purple

Red−Blue

Purple−Orange

Purple−Yellow

Blue−Yellow

Green−Yellow

Red−Yellow

Heat

Heat 2

Terrain

Terrain 2

Viridis

Plasma

Inferno

Dark Mint

Mint

BluGrn

Teal

TealGrn

Emrld

BluYl

ag_GrnYl

Peach

PinkYl

Burg

BurgYl

RedOr

OrYel

Purp

PurpOr

Sunset

Magenta

SunsetDark

ag_Sunset

BrwnYl

YlOrRd

YlOrBr

OrRd

Oranges

YlGn

YlGnBu

Reds

RdPu

PuRd

Purples

PuBuGn

PuBu

Greens

BuGn

GnBu

BuPu

Blues

Lajolla

Turku

Diverging

Blue−Red

Blue−Red 2

Blue−Red 3

Red−Green

Purple−Green

Purple−Brown

Green−Brown

Blue−Yellow 2

Blue−Yellow 3

Green−Orange

Cyan−Magenta

Tropic

Broc

Cork

Vik

Berlin

Lisbon

Tofino

Figure 2: Brief overview of available predefined palettes in colorspace.

Time

log(

EuS

tock

Mar

kets

)

1992 1993 1994 1995 1996 1997 1998

7.5

8.0

8.5

9.0

DAXSMICACFTSE

Class

Sur

vive

d

1st 2nd 3rd Crew

Yes

No

0.0

0.2

0.4

0.6

0.8

1.0

Figure 3: Using colorspace with base R graphics. Left: Time series plot of log-prices fromEuStockMarkets data with qualitative_hcl(4, "Dark 3") palette. Right: Spine plot withsurvival proportions across passenger classes in the titanice data with sequential_hcl(2,"Purples 3") palette.

2.2. Usage with base graphics

The color vectors returned by the HCL palette functions can usually be passed directly tomost base graphics function, typically through the col argument. Here, the q4 vector createdabove is used in a time series display (see the left panel of Figure 3):

R> plot(log(EuStockMarkets), plot.type = "single", col = q4, lwd = 2)R> legend("topleft", colnames(EuStockMarkets), col = q4, lwd = 3, bty = "n")

Page 5: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 5

0.0

0.4

0.8

1.2

5 6 7 8

Sepal.Length

dens

ity

Species

setosa

versicolor

virginica

●●●● ●●

●●●●●● ● ●●●● ●

●●●●● ●

● ●●● ●●● ●● ●● ●

●●● ●●●● ●●● ●●

● ●● ●●●

● ●●● ●●

●●●● ● ●● ●●●●●

●● ●● ●●

●●● ●●● ●●● ●●●

●● ● ●●● ●●● ● ●●

●●●●● ●

●● ●● ●● ●●●●●●

●●●● ●●

●● ●●●●

●● ●●● ●●●● ●● ●

●●● ●● ●●●●●●●

●● ●● ●●

● ●●● ●● ●● ●●● ●

●●● ●● ●

● ●●●●●

●● ●●●● ●●●●● ●

● ● ●● ●● ●●●●●●

● ●● ●●●

●● ●● ●● ●●● ●● ●

●● ●●●● ●● ●●●●

● ●

●● ●● ●●●●●● ●●

● ●●●● ●● ●●● ●●

● ●● ●● ●

●●●● ●●● ●● ●● ●

●●●● ● ●●● ●●●●

●●●●●●

●●● ●●●

● ●●●● ●●●●● ●●

●● ●●●●

●● ●● ●● ●●●●● ●

●● ●●●● ●● ●●●●

●●● ●●●

● ●●●● ●

● ●● ●●●●● ●●● ●

● ● ●●●●

● ● ●● ● ●● ●●● ●●

●● ● ●● ● ●●●●● ●

● ●● ●●●

●●● ●●● ● ●● ● ●●

● ● ●● ●●

●● ●● ● ●

● ● ●●●●●● ●●● ●

● ●●● ●● ●●●● ●●

●●● ● ●●

●● ●●●●● ●●● ● ●

● ●●● ●●

●●●●●●

●●●● ●●●● ● ●● ●

●●●●●●●●●● ●●●

●●● ●●●●●●● ●●●●●●●●●

●●●●●● ●●●●●●●●

●●●● ●●● ●● ●●●●● ●●●●●●●●● ●● ●●●●●●●

●●● ●●●●

●●●●●●●●●●●●● ●●● ●●●●

●●● ●●● ●● ●●●●●

●●●● ●●●

●●●●●●●● ●●● ●●

●● ●●●●●

●●●●● ●●

●●●● ●●●●●●●●●

●●● ●●●●●●●● ●●

●●●●●●●

●●●●●●● ●●●● ●●

●●●● ●● ●●●●●● ●

●●

●●● ●●●●●●● ●●

● ●●● ●●● ●● ●●●

●●● ●●●

●●●●● ●●●● ●● ●

●●●● ●●●● ●● ●●

● ●●● ●●

●● ●●●●

●● ●●●● ●●●●●●

● ●●●● ●

●●●●●● ●● ●●●●

●●●●●

●●●

● ●●●●●●●● ●●●

●●● ●●●● ●●●●●

●●●●●●

● ●●●●●●●●● ●●

●● ●●●●●●● ●●●

●●● ●●●

●●● ●●●

●● ●●●●● ●●●● ●

● ●● ●●●

●● ●●●● ●●● ● ●●

●● ●●●● ●●●●●●

0

5000

10000

15000

1 2 3

carat

pric

e

cut

Fair

Good

Very Good

Premium

Ideal

Figure 4: Using colorspace with ggplot2 graphics. Left: Kernel density of sepallength, grouped and shaded by species, in the iris data with semi-transparentscale_fill_discrete_qualitative(palette = "Dark 3") color scale. Right: Scat-ter plot of price by carat, shaded by cut levels, in a subsample of the diamondsdata with the scale_color_discrete_sequential(palette = "Purples 3", nmax = 6,order = 2:6) color scale.

As another example for a sequential palette, we demonstrate how to create a spine plot (seethe right panel of Figure 3) displaying the proportion of Titanic passengers that survivedper class. The "Purples 3" palette is used, which is quite similar to the ColorBrewer.org(Harrower and Brewer 2003) palette "Purples". Here, only two colors are employed, yieldinga dark purple and light gray.

R> ttnc <- margin.table(Titanic, c(1, 4))[, 2:1]R> spineplot(ttnc, col = sequential_hcl(2, palette = "Purples 3"))

2.3. Usage with ggplot2To provide access to the HCL color palettes from within ggplot2 graphics (Wickham 2016;Wickham et al. 2018) suitable discrete and/or continuous gglot2 color scales are provided.The scales are named via the scheme

scale_<aesthetic>_<datatype>_<colorscale>()

where

• <aesthetic> is the name of the aesthetic (fill, color, colour).• <datatype> is the type of the variable plotted (discrete or continuous).• <colorscale> sets the type of the color scale used (qualitative, sequential, diverging,

divergingx).

To illustrate their usage two simple examples are shown using the qualitative "Dark 3" andsequential "Purples 3" palettes that were also employed above. For the first example, semi-transparent shaded densities of the sepal length from the iris data are shown, grouped byspecies (see the left panel of Figure 4).

Page 6: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

6 colorspace: Manipulating and Assessing Colors and Palettes

R> library("ggplot2")R> ggplot(iris, aes(x = Sepal.Length, fill = Species)) ++ geom_density(alpha = 0.6) ++ scale_fill_discrete_qualitative(palette = "Dark 3")

And for the second example the sequential palette is used to code the cut levels in a scatterof price by carat in the diamonds data (or rather a small subsample thereof, see the rightpanel of Figure 4). The scale function first generates six colors but then drops the first colorbecause the light gray is too light here. (Alternatively, the chroma and luminance parameterscould also be tweaked.)

R> dsamp <- diamonds[1 + 1:1000 * 50, ]R> ggplot(dsamp, aes(carat, price, color = cut)) + geom_point() +R> scale_color_discrete_sequential(palette = "Purples 3",R> nmax = 6, order = 2:6)

2.4. Palette visualization and assessmentThe colorspace package also provides a number of functions that aid visualization and assess-ment of its palettes.

• demoplot() can display a palette (with arbitrary number of colors) in a range of typicaland somewhat simplified statistical graphics.

• hclplot() converts the colors of a palette to the corresponding hue/chroma/luminancecoordinates and displays them in HCL space with one dimension collapsed. The col-lapsed dimension is the luminance for qualitative palettes and the hue for sequen-tial/diverging palettes.

• specplot() also converts the colors to hue/chroma/luminance coordinates but drawsthe resulting spectrum in a line plot.

For the qualitative "Dark 3" palette from above the following plots can be obtained (seeFigure 5).

R> demoplot(q4, "bar")R> hclplot(q4)R> specplot(q4, type = "o")

The bar plot is used as a typical application for a qualitative palette (in addition to the timeseries and density plots used above). The other two displays show that luminance is (almost)constant in the palette while the hue changes linearly along the color “wheel”. Ideally, chromawould have also been constant to completely balance the colors. However, at this luminancethe maximum chroma differs across hues so that the palette is fixed up to use less chroma forthe yellow and green elements.Note also that in a bar plot areas are shaded (and not just points or lines) so that lightercolors would be preferable. In the density plot in Figure 4 this was achieved through semi-transparency. Alternatively, luminance could be increased as is done in the "Pastel 1" or"Set 3" palettes.Subsequently, the same types of assessment are carried out in Figure 6 for the sequential"Purples 3" palette as employed above.

Page 7: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 7

Figure 5: Palette visualization and assessment for qualitative_hcl(4, "Dark 3") palette.Left: Demo bar plot. Center: Hue-chroma plane at fixed L = 60 in HCL space. Right:HCL spectrum with linearly changing hue (around color wheel), almost constant chroma,and constant luminance.

Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3")palette. Left: Demo heatmap. Center: Chroma-luminance plane at fixed H = 270 inHCL space. Right: HCL spectrum with constant hue, triangular chroma, and increastingluminance.

R> s9 <- sequential_hcl(9, "Purples 3")R> demoplot(s9, "heatmap")R> hclplot(s9)R> specplot(s9, type = "o")

In Figure 6, a heatmap (based on the well-known Maunga Whau volcano data) is used asa typical application for a sequential palette. The elevation of the volcano is brought outclearly, using dark colors to give emphasis to higher elevations. The other two displays showthat hue is constant in the palette while luminance and chroma vary. Luminance increasesmonotonically from dark to light (as required for a proper sequential palette). Chroma istriangular-shaped which allows to better distinguish the middle colors in the palette whencompared to a monotonic chroma trajectory.

Page 8: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

8 colorspace: Manipulating and Assessing Colors and Palettes

3. Color spaces: S4 classes and utilitiesAt the core of the colorspace package are various utilities for computing with color spaces(Wikipedia 2019d), as the name conveys. Thus, the package helps to map various three-dimensional representations of color to each other (Ihaka 2003). A particularly importantmapping is the one from the perceptually-based and device-independent color model HCL(Hue-Chroma-Luminance) to standard Red-Green-Blue (sRGB) which is the basis for colorspecifications in many systems based on the corresponding hex codes (Wikipedia 2019i), e.g.,in HTML but also in R. For completeness further standard color models are included as wellin the package. The connections are illustrated in Figure 7. Color models that are (or try tobe) perceptually-based are displayed with circles and models that are not are displayed withrectangles.

3.1. Implemented color spaces

The color spaces, implemented in colorspace, along with their corresponding S4 classes andeponymous class constructors, are:

• RGB() for the classic Red-Green-Blue color model that mixes three primary colors withdifferent intensities to obtain a spectrum of colors. The advantage of this color model is(or was) that it corresponded to how computer and TV screens generated colors, henceit was widely adopted and still is the basis for color specifications in many systems.For example, the hex color codes are employed in HTML but also in R. However, theRGB model also has some important drawbacks: It does not take into account theoutput device properties, it is not perceptually uniform (a unit step within RGB doesnot produce a constant perceptual change in color), and it is unintuitive for humans tospecify colors (say brown or pink) in this space. See Wikipedia (2019g) for more details.

• sRGB() addresses the issue of device dependency by adopting a so-called gamma cor-rection. Therefore, the gamma-corrected standard RGB (sRGB), as opposed to thelinearized RGB above, is a good model for specifying colors in software and for hard-ware. But it is still unintuitive for humans to work directly with this color space.

polarLAB

polarLUV(= HCL)

LAB

LUV

XYZ RGB

HLS

HSV

sRGB hex

white point= D65

gamma(= 2.4)

Figure 7: Relationship between three-dimensional color spaces implemented in colorspace.Color models that are (or try to be) perceptually-based are displayed with circles, other colormodels with rectangles.

Page 9: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 9

Therefore, sRGB is a good place to end up in a color space manipulation but it is nota good place to start. See Wikipedia (2019h) for more details.

• HSV() is a simple transformation of the (s)RGB space that tries to capture the percep-tual axes: hue (dominant wavelength, the type of color), saturation (colorfulness), andvalue (brightness, i.e., light vs. dark). Unfortunately, the three axes in the HSV modelare confounded so that, e.g., brightness changes dramaticaly with hue. See Wikipedia(2019f) for more details.

• HLS() (Hue-Lightness-Saturation) is another transformation of (s)RGB that tries tocapture the perceptual axes. It does a somewhat better job but the dimensions are stillstrongly confounded. See Wikipedia (2019f) for more details.

• XYZ() was established by the CIE (Commission Internationale de l’Eclairage) based onpsychophysical experiments with human subjects. It provides a unique triplet of XYZvalues, coding the standard observer’s perception of the color. It is device-independentbut it is not perceptually uniform and the XYZ coordinates have no intuitive meaning.See Wikipedia (2019a) for more details.

• LUV() and LAB() were therefore proposed by the CIE as perceptually uniform colorspaces where the former is typically preferred for emissive technologies (such as screensand monitors) whereas the latter is usually preferred when working with dyes andpigments. However, the three axes of these two spaces still do not correspond to humanperceptual axes. See Wikipedia (2019c); Wikipedia (2019b) for more details.

• polarLUV() and polarLAB() take polar coordinates in the UV plane and AB plane,respectively. Specifically, the polar coordinates of the LUV model are known as theHCL (Hue-Chroma-Luminance) model. These capture the human perceptual axes verywell without confounding effects as in the HSV or HLS approaches. (More details followbelow.)

All S4 classes for color spaces inherit from a virtual class color which is internally alwaysrepresented by matrices with three columns (corresponding to the different three dimensions).Note that since the inception of the color space conversion tools within colorspace’s C codeby Ihaka (2003) other R tools for this purpose became available. Notably, base R meanwhileprovides grDevices::convertColor() (computed in high-level R, R Core Team 2018) andfarver::convert_colour() (Pedersen, Nicolae, and François 2018) is based on a C++ li-brary. For many basic color conversion purposes the colorspace package and these alternativesare essentially equally suitable (see the discussion in Zeileis, Gaslam, Murrell, and Pedersen2018). For more complex conversions, including different chromatic adaptation algorithms,a more comprehensive color science approach is implemented in the R package colorscience(Gama and Davis 2018). Finally, base R also provides grDevices::hcl() for mapping HCLrepresentations to hex codes.To make the colorspace package self-contained and exactly backward compatible, the C codein colorspace is still used as the basis for all color space conversions.

3.2. Utilities

For working with the implemented S4 color spaces various utilities are available:

• as() method: Conversions of a color object to the various color spaces, e.g., as(x,"sRGB").

Page 10: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

10 colorspace: Manipulating and Assessing Colors and Palettes

• coords(): Extract the three-dimensional coordinates pertaining to the current colorclass.

• hex(): Convert a color object to sRGB and code in a hex string that can be used withinR plotting functions.

• hex2RGB(): Convert a given hex color string to an sRGB color object which can alsobe coerced to other color spaces.

• readRGB() and readhex() can read text files into color objects, either from RGB coor-dinates or hex color strings.

• writehex(): Writes hex color strings to a text file.• whitepoint(): Query and change the white point employed in conversions from CIE

XYZ to RGB. Defaults to D65.

3.3. Illustration of basic colorspace functionality

As an example a vector of colors x can be specified in the HCL (or polar LUV) model:

R> (x <- polarLUV(L = 70, C = 50, H = c(0, 120, 240)))

L C H[1,] 70 50 0[2,] 70 50 120[3,] 70 50 240

The resulting three colors are pastel red (hue = 0), green (hue = 120), and blue (hue = 240)with moderate chroma and luminance. For display in other systems an sRGB representationmight be needed:

R> (y <- as(x, "sRGB"))

R G B[1,] 0.8931564 0.5853740 0.6465459[2,] 0.5266113 0.7224335 0.4590469[3,] 0.4907804 0.6911937 0.8673877

With coords(x) or coords(y) the displayed coordinates can also be extracted as numericmatrices. And from sRGB we can also coerce to HSV for example:

R> as(y, "HSV")

H S V[1,] 348.0750 0.3446008 0.8931564[2,] 104.6087 0.3645825 0.7224335[3,] 208.0707 0.4341857 0.8673877

For display in many systems (including R itself) hex color codes based on the sRGB coordi-nates can be created:

Page 11: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 11

Qualitative (Set 2)

Color

Desaturated

Sequential (Blues 3)

Color

Desaturated

Diverging (Green−Brown)

Color

Desaturated

Figure 8: Examples of palette types in colorspace. Qualitative palettes are balanced towardsthe same luminance level while sequential and diverging palettes go from dark to light and/orvice versa, respectively.

R> hex(x)

[1] "#E495A5" "#86B875" "#7DB0DD"

4. HCL-based color palettesAs motivated in the previous section, the HCL space is particularly useful for specifying indi-vidual colors and color palettes, as its three axes match those of the human visual system verywell. Therefore, the colorspace package provides three palette functions based on the HCLmodel: qualitative_hcl(), sequential_hcl(), and diverging_hcl(). Their constructionprinciples are exemplified in Figure 8 and explained in more detail below. The desaturatedpalettes in the second row of Figure 8 bring out clearly that luminance differences (= light-dark contrasts) are crucial for sequential and diverging palettes while qualitative palettes arebalanced at the same luminance.To facilitate obtaining good sets of colors, HCL parameter combinations that yield usefulpalettes are accessible by name. These can be listed using the function hcl_palettes():

R> hcl_palettes()

HCL palettes

Type: QualitativeNames: Pastel 1, Dark 2, Dark 3, Set 2, Set 3, Warm, Cold, Harmonic,

Dynamic

Type: Sequential (single-hue)Names: Grays, Light Grays, Blues 2, Blues 3, Purples 2, Purples 3, Reds

2, Reds 3, Greens 2, Greens 3, Oslo

Type: Sequential (multi-hue)Names: Purple-Blue, Red-Purple, Red-Blue, Purple-Orange, Purple-Yellow,

Blue-Yellow, Green-Yellow, Red-Yellow, Heat, Heat 2,Terrain, Terrain 2, Viridis, Plasma, Inferno, Dark Mint,Mint, BluGrn, Teal, TealGrn, Emrld, BluYl, ag_GrnYl, Peach,PinkYl, Burg, BurgYl, RedOr, OrYel, Purp, PurpOr, Sunset,Magenta, SunsetDark, ag_Sunset, BrwnYl, YlOrRd, YlOrBr,

Page 12: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

12 colorspace: Manipulating and Assessing Colors and Palettes

OrRd, Oranges, YlGn, YlGnBu, Reds, RdPu, PuRd, Purples,PuBuGn, PuBu, Greens, BuGn, GnBu, BuPu, Blues, Lajolla,Turku

Type: DivergingNames: Blue-Red, Blue-Red 2, Blue-Red 3, Red-Green, Purple-Green,

Purple-Brown, Green-Brown, Blue-Yellow 2, Blue-Yellow 3,Green-Orange, Cyan-Magenta, Tropic, Broc, Cork, Vik,Berlin, Lisbon, Tofino

To inspect the HCL parameter combinations for a specific palette simply include the palettename where upper- vs. lower-case, spaces, etc. are ignored for matching the label, i.e., "set2"matches "Set 2":

R> hcl_palettes(palette = "set2")

HCL paletteName: Set 2Type: QualitativeParameter ranges:h1 h2 c1 c2 l1 l2 p1 p2 cmax fixup0 NA 60 NA 70 NA NA NA NA TRUE

To compute the actual color hex codes (representing sRGB coordinates) based on these HCLparameters, the functions qualitative_hcl(), sequential_hcl(), and diverging_hcl()can be used. Either all parameters can be specified “by hand” through the HCL parameters,an entire palette can be specified “by name”, or the name-based specification can be modifiedby a few HCL parameters. In case of the HCL parameters, either a vector-based specificationsuch as h = c(0, 270) or individual parameters h1 = 0 and h2 = 270 can be used.The first three of the following commands lead to equivalent output. The fourth commandyields a modified set of colors (lighter due to a luminance of 80 instead of 70).

R> qualitative_hcl(4, h = c(0, 270), c = 60, l = 70)

[1] "#ED90A4" "#ABB150" "#00C1B2" "#ACA2EC"

R> qualitative_hcl(4, h1 = 0, h2 = 270, c1 = 60, l1 = 70)

[1] "#ED90A4" "#ABB150" "#00C1B2" "#ACA2EC"

R> qualitative_hcl(4, palette = "set2")

[1] "#ED90A4" "#ABB150" "#00C1B2" "#ACA2EC"

R> qualitative_hcl(4, palette = "set2", l = 80)

[1] "#FFACBF" "#C6CD70" "#32DDCD" "#C7BEFF"

Page 13: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 13

Qualitative

Pastel 1

Dark 2

Dark 3

Set 2

Set 3

Warm

Cold

Harmonic

Dynamic

Figure 9: Prespecified qualitative HCL palettes available in qualitative_hcl() in col-orspace.

4.1. Qualitative palettesAs suggested by Ihaka (2003) qualitative_hcl() distinguishes the underlying categories bya sequence of hues while keeping both chroma and luminance constant, to give each color in theresulting palette the same perceptual weight. Thus, h should be a pair of hues (or equivalentlyh1 and h2 can be used) with the starting and ending hue of the palette. Then, an equidistantsequence between these hues is employed, by default spanning the full color wheel (i.e., thefull 360 degrees). Chroma c (or equivalently c1) and luminance l (or equivalently l1) areconstants.Figure 9 shows the named palettes available in the qualitative_hcl() function. The firstfive palettes are close to the ColorBrewer.org palettes of the same name (Harrower and Brewer2003). They employ different levels of chroma and luminance and, by default, span the fullhue range. The remaining four palettes are taken from Ihaka (2003). They are based on thesame chroma (= 50) and luminance (= 70) but the hue is restricted to different intervals.

R> hcl_palettes("qualitative", plot = TRUE, nrow = 5)

When qualtitative palettes are employed for shading areas in statistical displays (e.g., inbar plots, pie charts, or regions in maps), lighter colors (with moderate chroma and highluminance) such as "Pastel 1" or "Set 3" are typically less distracting. By contrast, whencoloring points or lines, more flashy colors (with high chroma) are often required: On a whitebackground a moderate luminance as in "Dark 2" or "Dark 3" usually works better whileon a black/dark background the luminance should be higher as in "Set 2". Some exampleswith demo graphics are provided in Section 5.

4.2. Sequential palettes (single-hue)As suggested by Zeileis et al. (2009), sequential_hcl() codes the underlying numeric valuesby a monotonic sequence of increasing (or decreasing) luminance. Thus, the function’s largument should provide a vector of length 2 with starting and ending luminance (equivalently,l1 and l2 can be used). Without chroma (i.e., c = 0), this simply corresponds to a grayscalepalette like gray.colors(), see "Grays" and "Light Grays" in Figure 10.For adding chroma, a simple strategy would be to pick a single hue (via h or h1) and thendecrease chroma from some value (c or c1) to zero (i.e., gray) along with increasing luminance.For bringing out the extremes (a dark high-chroma color vs. a light gray) this is already veryeffective, see "Blues 2", "Purples 2", "Reds 2", and "Greens 2".

Page 14: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

14 colorspace: Manipulating and Assessing Colors and Palettes

Sequential (single−hue)

Grays

Light Grays

Blues 2

Blues 3

Purples 2

Purples 3

Reds 2

Reds 3

Greens 2

Greens 3

Oslo

Figure 10: Prespecified sequential single-hue HCL palettes available in sequential_hcl() incolorspace.

For distinguishing colors in the center of the palette, two strategies can be employed: (a) Huecan be varied as well by specifying an interval of hues in h (or beginning hue h1 and endinghue h2). More details are provided in the next section. (b) Instead of a decreasing chroma, atriangular chroma trajectory can be employed from c1 over cmax to c2 (equivalently specifiedas a vector c of length 3). This yields high-chroma colors in the middle of the palette thatare more easily distinguished from the dark and light extremes. See "Blues 3", "Purples3", "Reds 3", and "Greens 3" in Figure 10.Instead of employing linear trajectories in the chroma or luminance coordinates, some palettesemploy a power transformation of the chroma and/or luminance trajectory. Either a vectorpower of length 2 or separate p1 (for chroma) and p2 (for luminance) can be specified. If thelatter is missing, it defaults to the former.

R> hcl_palettes("sequential (single-hue)", n = 7, plot = TRUE, nrow = 6)

All except the last one are inspired by the ColorBrewer.org palettes with the same base name(Harrower and Brewer 2003) but restricted to a single hue only. They are intended for awhite/light background. The last palette ("Oslo") is taken from the scientific color maps ofCrameri (2018) and is intended for a black/dark background and hence the order is reversedstarting from a light blue (not a light gray).To distinguish many colors in a sequential palette it is important to have a strong contrast onthe luminance axis, possibly enhanced by an accompanying pronounced variation in chroma.When only a few colors are needed (e.g., for coding an ordinal categorical variable with fewlevels) then a lower luminance contrast may suffice.

4.3. Sequential palettes (multi-hue)

To not only bring out extreme colors in a sequential palette but also better distinguish middlecolors it is a common strategy to employ a sequence of hues. Thus, the basis of such a paletteis still a monotonic luminance sequence as above (combined with a monotonic or triangularchroma sequence). But rather than using a single hue, an interval of hues in h (or beginninghue h1 and ending hue h2) can be specified.sequential_hcl() allows combined variations in hue (h and h1/h2, respectively), chroma (cand c1/c2/cmax, respectively), luminance (l and l1/l2, respectively), and power transforma-

Page 15: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 15

Sequential (multi−hue)

Purple−Blue

Red−Purple

Red−Blue

Purple−Orange

Purple−Yellow

Blue−Yellow

Green−Yellow

Red−Yellow

Heat

Heat 2

Terrain

Terrain 2

Viridis

Plasma

Inferno

Dark Mint

Mint

BluGrn

Teal

TealGrn

Emrld

BluYl

ag_GrnYl

Peach

PinkYl

Burg

BurgYl

RedOr

OrYel

Purp

PurpOr

Sunset

Magenta

SunsetDark

ag_Sunset

BrwnYl

YlOrRd

YlOrBr

OrRd

Oranges

YlGn

YlGnBu

Reds

RdPu

PuRd

Purples

PuBuGn

PuBu

Greens

BuGn

GnBu

BuPu

Blues

Lajolla

Turku

Figure 11: Prespecified sequential multi-hue HCL palettes available in sequential_hcl() incolorspace.

tions for the chroma and luminance trajectories (power and p1/p2, respectively). This yieldsa broad variety of sequential palettes, including many that closely match other well-knowncolor palettes. Figure 11 shows all the named multi-hue sequential palettes in colorspace:

R> hcl_palettes("sequential (multi-hue)", n = 7, plot = TRUE)

• "Purple-Blue" to "Terrain 2" are various palettes created during the development ofcolorspace, e.g., by Zeileis et al. (2009) or Stauffer et al. (2015) among others.

• "Viridis" to "Inferno" closely match the palettes that Smith and Van der Walt (2015)developed for matplotlib and that gained popularity recently.

Page 16: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

16 colorspace: Manipulating and Assessing Colors and Palettes

Diverging

Blue−Red

Blue−Red 2

Blue−Red 3

Red−Green

Purple−Green

Purple−Brown

Green−Brown

Blue−Yellow 2

Blue−Yellow 3

Green−Orange

Cyan−Magenta

Tropic

Broc

Cork

Vik

Berlin

Lisbon

Tofino

Figure 12: Prespecified diverging HCL palettes available in diverging_hcl() in colorspace.

• "Dark Mint" to "BrwnYl" closely match palettes provided in CARTO (CARTO 2019).• "YlOrRd" to "Blues" closely match ColorBrewer.org palettes (Harrower and Brewer

2003).• "Lajolla" and "Turku" closely match the scientific color maps of the same name by

Crameri (2018) and are intended for a black/dark background.

Note that the palettes differ substantially in the amount of chroma and luminance con-trasts, respectively. For example, many palettes go from a dark high-chroma color to aneutral low-chroma color (e.g., "Reds", "Purples", "Greens", "Blues") or even light gray(e.g., "Purple-Blue"). But some palettes also employ relatively high chroma throughout thepalette (e.g., the viridis and many CARTO palettes). To emphasize the extremes the formerstrategy is typically more suitable while the latter works better if all values along the sequenceshould receive some more perceptual weight.

4.4. Diverging palettes

diverging_hcl() codes the underlying numeric values by a triangular luminance sequencewith different hues in the left and in the right “arm” of the palette. Thus, it can be seen asa combination of two sequential palettes with some restrictions: (a) a single hue is used foreach arm of the palette, (b) chroma and luminance trajectory are balanced between the twoarms, (c) the neutral central value has zero chroma. To specify such a palette a vector of twohues h (or equivalently h1 and h2), either a single chroma value c (or c1) or a vector of twochroma values c (or c1 and cmax), a vector of two luminances l (or l1 and l2), and powerparameter(s) power (or p1 and p2) are used. For more flexible diverging palettes withoutthe restrictrictions above (and consequently more parameters) see the divergingx_hcl()palettes introduced below.Figure 12 shows all such diverging palettes that have been named in colorspace:

R> hcl_palettes("diverging", n = 7, plot = TRUE, nrow = 10)

Page 17: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 17

Type H C L

Qualitative Linear Constant ConstantSequential Constant (= single-hue) or Linear (+ power) or Linear (+ power)

Linear (= multi-hue) Triangular (+ power)Diverging Constant (2×) Linear (+ power) or Linear (+ power)

Triangular (+ power)

Table 1: Types of trajectories used for the HCL coordinates to construct qualitative, se-quential, and diverging palettes, see Equations 1–3.

• "Blue-Red" to "Cyan-Magenta" have been developed for colorspace starting from Zeileiset al. (2009), taking inspiration from various other palettes, including more balancedand simplified versions of several ColorBrewer.org palettes (Harrower and Brewer 2003).

• "Tropic" closely matches the palette of the same name from CARTO (CARTO 2019).• "Broc" to "Vik" and "Berlin" to "Tofino" closely match the scientific color maps of

the same name by Crameri (2018), where the first three are intended for a white/lightbackground and the other three for a black/dark background.

When choosing a particular palette for a display similar considerations apply as for the se-quential palettes. Thus, large luminance differences are important when many colors are usedwhile smaller luminance contrasts may suffice for palettes with fewer colors etc.

4.5. Construction details

Table 1 summarizes which types of trajectories (constant, linear, triangular) are used for thethree HCL coordinates (hue H, chroma C, luminance L) to construct the different types ofpalettes (qualitative, sequential, and diverging).As emphasized in Figure 8, the luminance is probably the most important property for definingthe type of palette. It is constant for qualitative palettes, monotonic for sequential palettes(linear or a power transformation), or uses two monotonic trajectories (linear or a powertransformation) diverging from the same neutral value.The trajectories for the hue are also rather intuitive and straightforward for the three dif-ferent types of palettes (constant vs. linear). However, the chroma trajectories are probablymost complicated and least obvious from the examples above. Hence, the exact mathematicalequations underlying the chroma trajectories are given in the following (i.e., using the param-eters c1, c2, cmax, and p1, respectively) and are depicted in Figure 13. Analogous equationsapply for the other two coordinates.The trajectories are functions of the intensity i ∈ [0, 1] where 1 corresponds to the fullintensity:

Constant: c1 (1)

Linear: c2 − (c2 − c1) · i (2)

Triangular:{

c2 − (c2 − cmax) · ij if i ≤ j

cmax − (cmax − c1) · i−j1−j > j

(3)

Page 18: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

18 colorspace: Manipulating and Assessing Colors and Palettes

Constant

Intensity (i)

Coo

rdin

ate

1 0.5 0

020

4060

8010

0

c1

Linear

Intensity (i)

Coo

rdin

ate

1 0.5 0

020

4060

8010

0

c1

c2

p1 = 1p1 = 1.6

Triangular

Intensity (i)

Coo

rdin

ate

1 0.5 0

020

4060

8010

0

c1

cmax

c2

p1 = 1p1 = 1.6

Figure 13: Types of trajectories to construct HCL color palettes, exemplified for the chromacoordinates, see Equations 1–3.

where j is the intensity at which cmax is assumed. It is constructed such that the slope to theleft is minus the slope to the right of j:

j =(

1 + |cmax − c1||cmax − c2|

)−1

Instead of using a linear intensity i going from 1 to 0, one can replace i with ip1 in Equations 1–3. This then leads to power-transformed curves that add or remove chroma more slowly ormore quickly depending on whether the power parameter p1 is < 1 or > 1.The three types of trajectories are also depicted in Figure 13. Note that full intensity i = 1 ison the left and zero intensity i = 0 on the right of each panel. The concrete parameters are:

• Constant: c1 = 80.• Linear: c1 = 80, c2 = 10, p1 = 1 (solid) vs. p1 = 1.6 (dashed).• Triangular: c1 = 60, cmax = 80, c2 = 10, p1 = 1 (solid) vs. p1 = 1.6 (dashed).

Further discussion of these trajectories and how they can be visualized and assessed for agiven color palette is provided in Section 5.

4.6. Registering your own palettes

The hcl_palettes() already come with a wide range of predefined palettes to which cus-tomizations can be easily added. However, it might also be convenient to register a cus-tom palette so that it can subsequently be reused with a new dedicated name. This issupported by adding a register = "..." argument once to a call to qualitative_hcl(),sequential_hcl(), or diverging_hcl():

R> qualitative_hcl(3, palette = "set2", l = 80, register = "myset")

The new palette is then included in hcl_palettes():

R> hcl_palettes("Qualitative")

Page 19: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 19

HCL palettes

Type: QualitativeNames: Pastel 1, Dark 2, Dark 3, Set 2, Set 3, Warm, Cold, Harmonic,

Dynamic, myset

And can be used subsequently in qualitative_hcl() as well as the qualitative ggplot2 colorscales (see Section 2.3), e.g.,

R> qualitative_hcl(4, palette = "myset")

[1] "#FFACBF" "#C6CD70" "#32DDCD" "#C7BEFF"

Remarks:

• The number of colors in the palette that was used during registration is not actuallystored and can be modified subsequently. The same holds for arguments alpha andrev.

• When registering a new palette with an old name that was already available previously,the old palette gets overwritten. We recommend not to overwrite the palettes that arepredefined in the package (albeit it is technically possible).

• The registration of a palette is only stored for the current session. When R is restartedand/or the colorspace package reloaded, only the predefined palettes from the packageare available. Thus, to make a palette permanently available a registration R code likecolorspace::qualitative_hcl(3, palette = "set2", l = 80, register = "myset")can be placed in your .Rprofile or similar startup scripts.

4.7. Flexible diverging palettes

The divergingx_hcl() function provides more flexible diverging palettes by simply callingsequential_hcl() twice with prespecified sets of hue, chroma, and luminance parameters.Thus, it does not pose any restrictions that the two “arms” of the palette need to be balancedand also allows to go through a non-gray neutral color (typically light yellow). Consequently,the chroma/luminance paths can be rather unbalanced.Figure 14 shows all such flexible diverging palettes that have been named in colorspace:

R> divergingx_palettes(n = 7, plot = TRUE, nrow = 10)

• "ArmyRose" to "Tropic" closely match the palettes of the same name from CARTO(CARTO 2019).

• "PuOr" to "Spectral" closely match the palettes of the same name from ColorBrewer.org(Harrower and Brewer 2003).

• "Zissou 1" closely matches the palette of the same name from wesanderson (Ram andWickham 2018).

Page 20: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

20 colorspace: Manipulating and Assessing Colors and Palettes

Diverging (flexible)

ArmyRose

Earth

Fall

Geyser

TealRose

Temps

Tropic

PuOr

RdBu

RdGy

PiYG

PRGn

BrBG

RdYlBu

RdYlGn

Spectral

Zissou 1

Cividis

Figure 14: Prespecified flexible diverging HCL palettes available in divergingx_hcl() incolorspace.

• "Cividis" closely matches the palette of the same name from the viridis family (Garnier2018). Note that despite having two “arms” with blue vs. yellow colors and a low-chroma center color, this is probably better classified as a sequential palette due to themonotonic chroma going from dark to light. (See Section 4.8 for more details.)

Typically, the more restricted diverging_hcl() palettes should be preferred because theyare more balanced. However, by being able to go through light yellow as the neutral colorwarmer diverging palettes are available.

4.8. Approximating palettes from other packages

The flexible specification of HCL-based color palettes in colorspace allows to closely approx-imate color palettes from various other packages:

• ColorBrewer.org (Harrower and Brewer 2003) as provided by R package RColorBrewer(Neuwirth 2014). See demo("brewer", package = "colorspace").

• CARTO colors (CARTO 2019) as provided by R package rcartocolor (Nowosad 2018).See demo("carto", package = "colorspace").

• The viridis palettes of Smith and Van der Walt (2015) developed for matplotlib, as pro-vided by R package viridis (Garnier 2018). See demo("viridis", package ="colorspace").

• The scientific color maps of Crameri (2018) as provided by R package scico (Pedersenand Crameri 2018). See demo("scico", package = "colorspace").

The graphics resulting from the demos can also be viewed online at http://colorspace.R-Forge.R-project.org/articles/approximations.html.Figure 15 shows a selection of such approximations using specplot() (see also Section 5.2) fortwo blue/green/yellow palettes (RColorBrewer::brewer.pal(7, "YlGnBu") andviridis::viridis(7)) and two purple/red/yellow (rcartocolor::carto_pal(7,

Page 21: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 21

ColorBrewer.org: YlGnBu

020

4060

8010

0

0

090

180

270

360

Hue Chroma Luminance

HCL Spectrum

Chr

oma

/ Lum

inan

ce

Hue

viridis: Viridis

020

4060

8010

0

0

090

180

270

360

Hue Chroma Luminance

HCL SpectrumC

hrom

a / L

umin

ance

Hue

CARTO: ag_Sunset

020

4060

8010

0

0

−36

0−

180

018

036

0

Hue Chroma Luminance

HCL Spectrum

Chr

oma

/ Lum

inan

ce

Hue

viridis: Plasma0

2040

6080

100

0

−36

0−

180

018

036

0Hue Chroma Luminance

HCL Spectrum

Chr

oma

/ Lum

inan

ce

Hue

Figure 15: HCL spectrum of four palettes taken from ColorBrewer.org, CARTO, and viridis(top swatches, solid lines) along with their HCL-based approximations (bottom swatches,dashed lines).

"ag_Sunset") and viridis::plasma(7)). Each panel compares the hue, chroma, and lu-minance trajectories of the original palettes (top swatches, solid lines) and their HCL-basedapproximations (bottom swatches, dashed lines). The palettes are not identical but veryclose for most colors. Note that also the chroma trajectories from the HCL palettes (greendashed lines) have some kinks which are due to fixing HCL coordinates at the boundaries ofadmissible RGB colors.Furthermore, Figure 15 illustrates what sets the viridis palettes apart from other sequentialpalettes. While the hue and luminance trajectories of "Viridis" and "YlGnBu" are verysimilar, the chroma trajectories differ: While lighter colors (with high luminance) have lowchroma for "YlGnBu", they have increasing chroma for "Viridis". Similarly, "ag_Sunset"

Page 22: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

22 colorspace: Manipulating and Assessing Colors and Palettes

viridis: Cividis

020

4060

8010

0

0

090

180

270

360

Hue Chroma Luminance

HCL Spectrum

Chr

oma

/ Lum

inan

ce

Hue

Figure 16: HCL spectrum of viridis::cividis (top swatch, solid lines) along with an HCL-based approximation (bottom swatch, dashed lines).

and "Plasma" have similar hue and luminance trajectories but different chroma trajectories.The result is that the viridis palettes have rather high chroma throughout which does notwork as well for sequential palettes on a white/light background as all shaded areas conveyhigh “intensity”. However, they work better on a dark/black background (see Figure 26).Also, they might be a reasonable alternative for qualitative palettes when grayscale printingshould also work.Another somewhat nonstandard palette from the viridis family is the cividis palette basedon blue and yellow hues and hence safe for red-green deficient viewers. Figure 16 shows thecorresponding specplot() along with an HCL-based approximation. What is unusual aboutthis palette: The hue and chroma trajectories would suggest a diverging palette, as there aretwo “arms” wth different hues and a zero-chroma point in the center. However, the luminancetrajectory clearly indicates a sequential palette as colors go monotonically from dark to light.Due to this unusual mixture the palette cannot be composed using the trajectories fromTable 1.However, the tools in colorspace can still be employed to easily reconstruct the palette. Onestrategy would be to set up the trajectories manually, using a linear luminance, piecewiselinear chroma, and piecewise constant hue:

R> cividis_hcl <- function(n) {+ i <- seq(1, 0, length.out = n)+ hex(polarLUV(+ L = 92 - (92 - 13) * i,+ C = approx(c(1, 0.9, 0.5, 0), c(30, 50, 0, 95), xout = i)$y,+ H = c(255, 75)[1 + (i < 0.5)]+ ), fix = TRUE)+ }

Instead of constructing the hex code from the HCL coordinates via hex(polarLUV(L, C,

Page 23: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 23

H)) from colorspace, the base R function hcl(H, C, L) from grDevices could also be used.In addition to manually setting up a dedicated function cividis_hcl(), it is possible toapproximate the palette using divergingx_hcl() (see Section 4.7), e.g.,

R> divergingx_hcl(n,R> h1 = 255, h2 = NA, h3 = 75,R> c1 = 30, cmax1 = 47, c2 = 0, c3 = 95,R> l1 = 13, l2 = 52, l3 = 92,R> p1 = 1.1, p3 = 1.0R> )

This uses a slight power transformation with p1 = 1.1 in the blue arm of the palette but oth-erwise essentially corresponds to what cividis_hcl() does. For convenience divergingx_hcl(n,palette = "Cividis") is preregistered using the above parameters.

4.9. HCL (and HSV) color palettes corresponding to base R palettes

To facilitate switching from base R palette functions to the HCL-based palettes above, col-orspace provides a few convenience interfaces:

• rainbow_hcl(): Convenience interface to qualitative_hcl() for a HCL-based “rain-bow” palette to replace the (in)famous rainbow() palette.

• heat_hcl(): Convenience interface to sequential_hcl() with default parameters cho-sen to generate more balanced heat colors than the basic heat.colors() function.

• terrain_hcl(): Convenience interface to sequential_hcl() with default parameterschosen to generate more balanced terrain colors than the basic terrain.colors() func-tion.

• diverging_hsv(): Diverging palettes generated in HSV space rather than HCL spaceas in diverging_hcl(). This is provided for didactic purposes to contrast the morebalanced HCL palettes with the more flashy and unbalanced HSV palettes.

5. Palette visualization and assessmentThe colorspace package provides several visualization functions for depicting one or morecolor palettes and their underlying properties. Color palettes can be visualized by:

• swatchplot(): Color swatches.• specplot(): Spectrum of HCL and/or RGB trajectories.• hclplot(): Trajectories in 2-dimensional HCL space projections.• demoplot(): Illustrations of typical (and simplified) statistical graphics.

5.1. Color swatches

The function swatchplot() is a convenience function for displaying collections of palettesthat can be specified as lists or matrices of hex color codes. Essentially, it is just a call tothe base graphics rect() function but with heuristics for choosing default labels, margins,

Page 24: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

24 colorspace: Manipulating and Assessing Colors and Palettes

Single−hue

Blues 2

Purples 2

Reds 2

Greens 2

Single−hue (advanced)

Blues 3

Purples 3

Reds 3

Greens 3

Multi−hue (advanced)

Blues

Purples

Reds

Greens

Figure 17: Variations of blue, purple, red, and green palettes with single hue and monotonicchroma (left), single hue and triangular chroma (center), and multiple hues and triangularchroma (right).

spacings, borders, etc. These heuristics are selected to work well for hcl_palettes() andmight need further tweaking in future versions of the package. Thus, Figures 1–2 as well asFigures 8–12 all use swatchplot() internally. For a simple stand-alone illustration consider:swatchplot("Palette" = sequential_hcl(5)).Next, we demonstrate a more complex example of a swatchplot() with three matrices ofsequential color palettes of blues, purples, reds, and greens (see Figure 17). For all palettes,luminance increases monotonically to yield a proper sequential palette. However, the hue andchroma handling is somewhat different to emphasize different parts of the palette.

• Single-hue: In each palette the hue is fixed and chroma decreases monotonically (alongwith increasing luminance). This is typically sufficient to clearly bring out the extremecolors (dark/colorful vs. light gray).

• Single-hue (advanced): The hue is fixed (as above) but the chroma trajectory is trian-gular. Compared to the basic single-hue palette above this allows to better distinguishthe colors in the middle and not only the extremes.

• Multi-hue (advanced): As in the advanced single-hue palette the chroma trajectoryis triangular but additionally the hue varies slightly. This can further enhance thedistinction of colors in the middle of the palette.

R> bprg <- c("Blues", "Purples", "Reds", "Greens")R> swatchplot(+ "Single-hue" = t(sapply(paste(bprg, 2), sequential_hcl, n = 7)),+ "Single-hue (advanced)" = t(sapply(paste(bprg, 3), sequential_hcl, n = 7)),+ "Multi-hue (advanced)" = t(sapply(bprg, sequential_hcl, n = 7)),+ nrow = 5, line = 5)

5.2. HCL (and RGB) spectrum

As the properties of a palette in terms of the perceptual dimensions hue, chroma, and lumi-nance are not always clear from looking just at color swatches or (statistical) graphics basedon these palettes, the specplot() function provides an explicit display for the coordinates ofthe HCL trajectory associated with a palette. This can bring out clearly various aspects, e.g.,

Page 25: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 250.

00.

20.

40.

60.

81.

0

Index

0

Red Green Blue

RGB Spectrum

Red

/ G

reen

/ B

lue

020

4060

8010

0

0

090

180

270

360

Hue Chroma Luminance

HCL Spectrum

Chr

oma

/ Lum

inan

ce

Hue

0.0

0.2

0.4

0.6

0.8

1.0

Index

0

Red Green Blue

RGB Spectrum

Red

/ G

reen

/ B

lue

050

100

150

0

−36

0−

180

018

036

0

Hue Chroma Luminance

HCL Spectrum

Chr

oma

/ Lum

inan

ce

Hue

Figure 18: HCL spectrum of the balanced diverging "Green-Brown" palette (left panel) andthe (in)famous and rather unbalanced rainbow() palette (right panel).

whether hue is constant, chroma is monotonic or triangular, and whether luminance is ap-proximately constant (as in many qualitative palettes), monotonic (as in sequential palettes),or diverging.The function first transforms a given color palette to its HCL (polarLUV()) coordinates. Asthe hues for low-chroma colors are not (or only poorly) identified, by default a smoothing isapplied to the hues. Also, to avoid jumps from 0 to 360 or vice versa, the hue coordinates areshifted suitably. By default, the resulting trajectories in the HCL spectrum are visualized bya simple line plot:

• Hue is drawn in red and coordinates are indicated on the axis on the right with range[0, 360] or (if necessary) [−360, 360].

• Chroma is drawn in green with coordinates on the left axis. The range [0, 100] is usedunless the palette necessitates higher chroma values.

• Luminance is drawn in blue with coordinates on the left axis in the range [0, 100].

Additionally, a color swatch for the palette is included. Optionally, a second spectrum for thecorresponding trajectories of RGB coordinates can be included. However, this is usually justof interest for palettes created in RGB space (or simple transformations of RGB).As spectrum plots have already been used for illustration in Figures 5 (for a qualitativepalette) as well as 6 and 15 (for sequential palettes), this section only provides a couple ofadditional illustrations. The diverging "Green-Brown" palette is depicted in the left panel

Page 26: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

26 colorspace: Manipulating and Assessing Colors and Palettes

of Figure 18. It simply combines a green and a brown/yellow sequential single-hue palette,both with triangular chroma trajectory. Hue is constant in each “arm” of the palette andthe chroma/luminance trajectories are rather balanced between both arms. In the center thepalette passes through a light gray (with zero chroma) as the neutral value. By including thecorresponding RGB spectrum in the top panel, it also becomes apparent that choosing suchwell-balanced palettes through trajectories in RGB color space is not straightforward. Thisbalanced palette – based on relatively simple HCL trajectories – is contrasted with a poorly-balanced palette – based on simple linear RGB trajectories in the right panel of Figure 18.This depicts the RGB and HCL spectrum of the (in)famous RGB rainbow palette. (SeeHawkins et al. 2014, for a plea why the RGB rainbow palette should be avoided in almostall scientific graphics.)

R> specplot(diverging_hcl(100, "Green-Brown"), rgb = TRUE)R> specplot(rainbow(100), rgb = TRUE)

The RGB spectrum of the rainbow palette shows that the trajectories are quite simple inRGB space but lead to substantial variations in chroma and (more importantly) luminance.This is why this palette is not suitable for encoding underlying data in statistical graphics.See also the related discussion of color vision deficiency in Section 6.

5.3. Trajectories in HCL spaceWhile the specplot() function above works well for bringing out the HCL coordinates as-sociated with a given palette, it does not show how the palette fits into the HCL space. Forexample, it is not so clear whether high chroma values are close to the maximum possible fora given hue. Thus, it cannot be judged so easily how the parameters of the hue, chroma, andluminance trajectories can be modified to obtain another palette.Therefore, the hclplot() is another visualization of the HCL coordinates associated witha palette. It does so by collapsing over one of the coordinates (either the hue H or theluminance L) and displays a heatmap of colors combining the remaining two dimensions.The coordinates for the given color palette are highlighted to bring out its trajectory. In casethe hue is really fixed (as in single-hue sequential palettes) or the luminance is really fixed (asin the qualitative palettes), collapsing is straightforward. However, when the coordinate thatis collapsed over is actually not constant in the palette, a simple bivariate linear model is usedto capture how the collapsed coordinate varies along with the two displayed coordinates.The function hclplot() has been designed to work well with the hcl_palettes() in thispackage. While it is possible to apply it to other color palettes as well, the results mightlook weird or confusing if these palettes are constructed very differently (e.g., like the highly-saturated base R palettes). To infer the default type of projection hclplot() assesses theluminance trajectory and sets the default correspondingly:

• type = "qualitative" if luminance is approximately constant.• type = "sequential" if luminance is monotonic.• type = "diverging" if luminance is diverging with two monotonic “arms” in the tra-

jectory.

Thus, for qualitative palettes – where luminance and chroma are fixed – the varying hue isdisplayed in a projection onto the hue-chroma plane at a given fixed luminance (Figure 19):

Page 27: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 27

Figure 19: Hue-chroma plane with luminance fixed at L = 70 along with the qualitative"Dynamic" palette with varying hue H and chroma fixed at C = 50.

Figure 20: Luminance-chroma plane with variations of blue sequential single-hue palettes(similar to "Blues 2" and "Blues 3"). Left: Linear chroma for H = 260. Center: Triangularchroma for H = 245. Right: Power-transformed triangular chroma for H = 245.

Figure 21: Luminance-chroma plane with blue multi-hue palette and triangular chroma (left),blue-yellow multi-hue palette and linear chroma (center), and diverging blue-red palette withbalanced linear chroma.

Page 28: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

28 colorspace: Manipulating and Assessing Colors and Palettes

R> hclplot(qualitative_hcl(9, "Dynamic"))

Figure 20 compares three single-hue sequential palettes by projection to the luminance-chromaplane for the given fixed hue. In the left panel the hue 260 is used with a simple linear chromatrajectory. The other two panels employ a triangular chroma trajectory for hue 245, eitherwith a piecewise-linear (center) or power-transformed (right) trajectory.

R> par(mfrow = c(1, 3))R> hclplot(sequential_hcl(7, h = 260, c = 80, l = c(35, 95), power = 1))R> hclplot(sequential_hcl(7, h = 245, c = c(40, 75, 0), l = c(30, 95),+ power = 1))R> hclplot(sequential_hcl(7, h = 245, c = c(40, 75, 0), l = c(30, 95),+ power = c(0.8, 1.4)))

Note that for H = 260 it is possible to go to dark colors (= low luminance) with high chromawhile this is not possible to the same extent for H = 245 due to the distorted shape of the HCLspace. Hence, chroma has to be decreased when proceeding to the dark low-luminance colors.Finally, Figure 21 compares two multi-hue sequential palettes along with a diverging palette.

R> par(mfrow = c(1, 3))R> hclplot(sequential_hcl(7, h = c(260, 220), c = c(50, 75, 0),+ l = c(30, 95), power = 1))R> hclplot(sequential_hcl(7, h = c(260, 60), c = 60, l = c(40, 95),+ power = 1))R> hclplot(diverging_hcl(7, h = c(260, 0), c = 80, l = c(35, 95),+ power = 1))

The multi-hue palette on the left employs a small hue range, resulting in a palette of “blues”just with slightly more distinction of the middle colors in the palette. In contrast, the multi-hue “blue-yellow” palette in the center panel uses a large hue range, resulting in more colorcontrasts throughout the palette. Finally, the balanced diverging palette in the right panelis constructed from two simple single-hue sequential palettes (for hues 260/blue and 0/red)that are completely balanced between the two “arms” of the palette.

5.4. Demonstration of statistical graphics

To demonstrate how different kinds of color palettes work in different kinds of statisticaldisplays, demoplot() provides a simple convenience interface to some base graphics with(mostly artificial) data sets. As a first overview, Figure 22 displays all built-in demos withthe same sequential heat colors palette: sequential_hcl(5, "Heat"). All types of demoscan, in principle, deal with arbitrarily many colors from any palette but clearly the graphicsdiffer in various respects such as:

• Work best for fewer colors (e.g., bar, pie, scatter, lines, . . . ) vs. many colors (e.g.,heatmap, perspective, . . . ).

• Intended for categorical data (e.g., bar, pie, . . . ) vs. continuous numeric data (e.g.,heatmap, perspective, . . . ).

• Shading areas (e.g., map, bar, pie, . . . ) vs. shading points or lines (scatter, lines).

Page 29: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 29

map heatmap

●●

● ●

●●●●

●●●

●● ●

●●●

● ●●

●●

●●

●●

●●

●●

●●

●●

●●●

●●

●●

●● ●

●●

●●●

● ●●●

●●

●●

● ●

●●

●●

●●●

●●

●●

●●

●●

●●

●●

●●

●●●●●

●●

●●●

●●

●●

●●

● ●

●●

●●

●●

●●● ●

●●●

●●

●●

●●

●●

●●

●● ●●

●●

●●●●●

●●

●● ●●

● ●

●●

●● ●

● ●

●●●●

● ●

●●●●

●●

●●●

●●

●●

● ●

●●

●●

●●

●●

●●

●●

● ●●

● ●

●● ●●

●●

●●●

●●● ●●

●●

●● ●

● ● ●●

●●

●●●

●●

●●●

●● ●

●●●

●●

●●

●●

●●●

● ●

●●

●● ●

●●

●● ●●●

●●

●●●

●●● ●

●●●

●●●●

● ●● ●

●● ●

●●● ●

●● ●

●●

●●●●

● ●●●

●●

●●

●●

scatter

spine bar pie

perspective mosaic lines

Figure 22: All built-in demoplot types with the same sequential_hcl(5, "Heat") palette.

Hence, in the following some further illustrations are organized by type of palette, usingsuitable demos for the particular palettes.Qualitative palettes: Light pastel colors typically work better for shading areas (pie, left) whiledarker and more colorful palettes are usually preferred for points (center) or lines (right).

R> par(mfrow = c(1, 3))R> demoplot(qualitative_hcl(4, "Pastel 1"), type = "pie")R> demoplot(qualitative_hcl(4, "Set 2"), type = "scatter")R> demoplot(qualitative_hcl(4, "Dark 3"), type = "lines")

Sequential palettes: Heatmaps (left) or perspective plots (center) often employ almost con-

Page 30: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

30 colorspace: Manipulating and Assessing Colors and Palettes

●●

●●

●●

●●

●●●

●● ●

●●●

● ●●

●●

●●

●●

●●

●●

●●

●●

●●●

●●

●● ●

●●

●●

● ●●●

●●

●●

● ●

●●

●●

●●●

●●

●●

●●

●●

●●

●●

●●

●●●●●

●●

●●●

●●

●●

● ●

●●

●●

●●

● ●

●●●

●●

●●

●●

●●

●● ●●

●●

●●●●

●●

● ●●

● ●

●●

●● ●

● ●

●●●●

● ●

●●

●●

●●

●●●

●●

●●

● ●

●●

●●

●●

●●

●●

●●

● ●●

● ●

●●

●●

●●

●●●

●● ●●

●●

● ●●

● ● ●●

●●

●●●

●●

●●●

●● ●

●●

●●

●●

●●

●●●

● ●

●●

●● ●

●●

●● ●●●

●●

●●●

●●● ●

●●●

●●●●

● ●● ●

●● ●

●●● ●

● ●●

●●

●●●

● ●●●

●●

●●

●●

Figure 23: Examples for demoplot() with different qualitative_hcl() palettes.

Figure 24: Examples for demoplot() with different sequential_hcl() palettes.

Figure 25: Examples for demoplot() with different diverging_hcl() palettes.

tinuous gradients with strong luminance contrasts. In contrast, when only a few orderedcategories are to be displayed (e.g., in a spine plot, right) more colorful sequential paletteslike the viridis palette can be useful.

R> par(mfrow = c(1, 3))R> demoplot(sequential_hcl(99, "Purple-Blue"), type = "heatmap")R> demoplot(sequential_hcl(99, "Reds"), type = "perspective")R> demoplot(sequential_hcl( 4, "Viridis"), type = "spine")

Diverging palettes: In some displays (such as the map, left), it is useful to employ an almostcontinuous gradient with strong luminance contrast to bring out the extremes. Here, thiscontrast is amplified by a larger power transformation emphasizing the extremes even fur-ther. In contrast, when fewer colors are needed more colorful palettes with lower luminancecontrasts can be desired. This is exemplified by a mosaic (center) and bar plot (right).

Page 31: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 31

●●

●●

●●

●●

●●●

●● ●

●●●

● ●●

●●

●●

●●

●●

●●

●●

●●

●●●

●●

●● ●

●●

●●

● ●●●

●●

●●

● ●

●●

●●

●●●

●●

●●

●●

●●

●●

●●

●●

●●●●●

●●

●●●

●●

●●

● ●

●●

●●

●●

● ●

●●●

●●

●●

●●

●●

●● ●●

●●

●●●●

●●

● ●●

● ●

●●

●● ●

● ●

●●●●

● ●

●●

●●

●●

●●●

●●

●●

● ●

●●

●●

●●

●●

●●

●●

● ●●

● ●

●●

●●

●●

●●●

●● ●●

●●

● ●●

● ● ●●

●●

●●●

●●

●●●

●● ●

●●

●●

●●

●●

●●●

● ●

●●

●● ●

●●

●● ●●●

●●

●●●

●●● ●

●●●

●●●●

● ●● ●

●● ●

●●● ●

● ●●

●●

●●●

● ●●●

●●

●●

●●

Figure 26: Examples for demoplot() with different palettes that work well on a black/darkbackground.

R> par(mfrow = c(1, 3))R> demoplot(diverging_hcl(99, "Tropic", power = 2.5), type = "map")R> demoplot(diverging_hcl( 5, "Green-Orange"), type = "mosaic")R> demoplot(diverging_hcl( 5, "Blue-Red 2"), type = "bar")

Figures 23–25 focused on palettes designed for light/white backgrounds. Therefore, to con-clude, some palettes are highlighted in Figure 26 that work well on dark/black backgrounds.

R> par(mfrow = c(2, 3), bg = "black")R> demoplot(sequential_hcl(9, "Oslo"), "heatmap")R> demoplot(sequential_hcl(9, "Turku"), "heatmap")R> demoplot(sequential_hcl(9, "Inferno", rev = TRUE), "heatmap")R> demoplot(qualitative_hcl(9, "Set 2"), "lines")R> demoplot(diverging_hcl(9, "Berlin"), "scatter")R> demoplot(diverging_hcl(9, "Cyan-Magenta", l2 = 20), "lines")

Page 32: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

32 colorspace: Manipulating and Assessing Colors and Palettes

6. Color vision deficiency emulationUsing the physiologically-based model for simulating color vision deficiency (CVD) of Machado,Oliveira, and Fernandes (2009) different kinds of limitations can be emulated: deuteranope(green cone cells defective), protanope (red cone cells defective), and tritanope (blue conecells defective).Below we briefly describe our R interface to these emulation techniques and show them in prac-tice for a heatmap with sequential palette. Another diverging palette example is available athttp://colorspace.R-Forge.R-project.org/articles/color_vision_deficiency.html.Finally, CVD emulation is particularly useful for bringing out why the RGB rainbow paletteis almost always a bad choice in scientific displays. See http://colorspace.R-Forge.R-project.org/articles/endrainbow.html for further illustrations.

6.1. R functions

The workhorse function to emulate color-vision deficiency is simulate_cvd(), which can takeany vector of valid R colors and transform them according to a certain CVD transformationmatrix and transformation equation. The transformation matrices have been established byMachado et al. (2009) and are provided in objects protanomaly_cvd, deutanomaly_cvd, andtritanomaly_cvd. The convenience interfaces deutan(), protan(), and tritan() are thehigh-level functions for simulating the corresponding kind of color blindness with a givenseverity (calling simulate_cvd() internally).For further guidance on color blindness in relation to statistical graphics see Lumley (2006)which accompanies the R package dichromat (Lumley 2013) and is based on earlier emulationtechniques (Viénot, Brettel, Ott, M’Barek, and Mollon 1995; Brettel, Viénot, and Mollon1997; Viénot, Brettel, and Mollon 1999).

6.2. Illustration: Heatmap with sequential palette

To illustrate that poor color choices can severely reduce the usefulness of a statistical graphicfor readers with color vision deficiencies, we employ the infamous RGB rainbow color palettein a heatmap. In base R this can be generated by rainbow(11, end = 2/3) ranging fromred (for high values) to blue (for low values). The poor results for the RGB rainbow paletteare contrasted in Figure 28 with a proper sequential palette ranging from dark blue to lightyellow: sequential_hcl(11, "Blue-Yellow").

Figure 27: Perspective visualization of Maunga Whau volcano data (Mount Eden, Auckland,New Zealand).

Page 33: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 33

Original

rainbow(11, end = 2/3) sequential_hcl(11, "Blue−Yellow")

Desaturated

Deuteranope

Protanope

Tritanope

Figure 28: Heatmap of Maunga Whau volcano data with RGB rainbow (left) and HCL-basedblue-yellow palette (right). The first row shows the original color palettes while subsequentrows emulate various color deficiencies.

Page 34: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

34 colorspace: Manipulating and Assessing Colors and Palettes

The statistical graphic employed for illustration is a heatmap of the well-known MaungaWhauvolcano data from base R. This heatmap is easily available as demoplot(..., "heatmap")where ... is the color vector to be used, e.g.,

R> rainbow(11, end = 2/3)

[1] "#FF0000FF" "#FF6600FF" "#FFCC00FF" "#CCFF00FF" "#66FF00FF"[6] "#00FF00FF" "#00FF66FF" "#00FFCCFF" "#00CCFFFF" "#0066FFFF"

[11] "#0000FFFF"

R> deutan(rainbow(11, end = 2/3))

[1] "#5D4700FF" "#B58C01FF" "#FFD005FF" "#FFE408FF" "#FFC809FF"[6] "#DBAB0AFF" "#C4B06DFF" "#ACB5D0FF" "#7595FFFF" "#1D50FBFF"

[11] "#000CF7FF"

and so on. To aid the interpretation of the heatmap a perspective display using only grayshades is provided in Figure 27, providing another intuitive display of what the terrain aroundMaunga Whau looks like.Subsequently, all combinations of palette and color vision deficiency are visualized. Addi-tionally, a grayscale version is created with desaturate(). This clearly shows how poorlythe RGB rainbow performs, often giving quite misleading impressions of what the terrainaround Maunga Whau looks like. In contrast, the HCL-based blue-yellow palette works rea-sonably well in all settings. The most important problem of the RGB rainbow is that it is notmonotonic in luminance, making correct interpretation quite hard. Moreover, the red-greencontrasts deteriorate substantially in the dichromatic emulations.

7. Apps for choosing colors and palettes interactivelyTo facilitate exploring the package and employing it when working with colors, several graph-ical user interfaces (GUIs) are provided within the package as shiny apps (Chang et al. 2018).All of these GUIs/apps can either be run locally from within R but are also provided onlineat http://hclwizard.org/.

• Palette constructor: choose_palette() or hclwizard() or hcl_wizard().• Color picker: choose_color() or equivalently hcl_color_picker().• Color vision deficiency emulator: cvd_emulator().

In addition to the shiny version, the palette constructor app is also available as a Tcl/Tk GUIvia R package tcltk shipped with base R (R Core Team 2018). The tcltk version can only berun locally and is considerably faster while the shiny version has a nicer interface with morefeatures and can be run online. The choose_palette() function by default starts the tcltkversion while hclwizard()/hcl_wizard() by default start the shiny version.

Page 35: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 35

Figure 29: App for interactively choosing HCL-based color palettes:choose_color()/hclwizard().

7.1. Choose palettes with the HCL color model

The shiny version of this GUI is shown in Figure 29. It interfaces the qualitative_hcl(),sequential_hcl(), and diverging_hcl() palettes from Section 4. The GUIs allow for inter-active modification of the arguments of the respective palette-generating functions, i.e., start-ing/ending hue, minimal/maximal chroma, minimal maximal luminance, and power transfor-mations that control how quickly/slowly chroma and/or luminance are changed through thepalette. Subsets of the parameters may not be applicable depending on the type of palettechosen.Optionally, the active palette can be illustrated by using a specplot() (see Section 5.2),hclplot() (see Section 5.3), or demoplot() (see Section 5.4), and assessed using emulationof color vision deficiencies (see Section 6). To facilitate generation of palettes for black/darkbackgrounds, a “dark mode” of the GUIs is also available.

7.2. Choose individual colors with the HCL color model

This GUI can be started with either choose_color() or equivalently hcl_color_picker().It shows the HCL color space either as a hue-chroma plane for a given luminance value or asa luminance-chroma plane for a given hue. Colors can be entered by:

• Clicking on a color coordinate in the hue-chroma or luminance-chroma plane.• Specifying the hue/chroma/luminance values via sliders.• Entering an RGB hex code.

By repeating the selection a palette of colors can be constructed and returned within R forsubsequent usage in visualizations.

Page 36: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

36 colorspace: Manipulating and Assessing Colors and Palettes

Figure 30: App for interactively choosing individual colors in HCL space:choose_color()/hcl_color_picker().

7.3. Emulate color vision deficiencies

This GUI can be started with cvd_emulator(). It allows to upload a raster image in JPGor PNG format which is then checked for various kinds of color vision deficiencies at theselected severity. By default the severity is set to 100% and all supported kinds of colorvision deficiency are checked for.

8. Color manipulation and utilitiesThe colorspace package provides several color manipulation utilities that are useful for creat-ing, assessing, or transforming color palettes, namely:

• desaturate(): Desaturate colors by chroma removal in HCL space.• darken() and lighten(): Algorithmically lighten or darken colors in HCL and/or HLS

space.• max_chroma(): Compute maximum chroma for given hue and luminance in HCL space.• mixcolor(): Additively mix two colors by computing their convex combination.

Page 37: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 37

Figure 31: App for emulating color vision deficiencies for uploaded raster images:cvd_emulator().

8.1. Desaturation in HCL space

Desaturation should map a given color to the gray with the same “brightness”. In principle,any perceptually-based color model (HCL, HLS, HSV, . . . ) could be employed for this butHCL works particularly well because its coordinates capture the perceptual properties betterthan most other color models.The desaturate() function converts any given hex color code or named R color to the cor-responding HCL coordinates and sets the chroma to zero. Thus, only the luminance matterswhich captures the “brightness” mentioned above. Finally, the resulting HCL coordinates aretransformed back to hex color codes for use in R. First, desaturate() is used to desaturatea vector of R color names:

R> desaturate(c("white", "orange", "blue", "black"))

[1] "#FFFFFF" "#B8B8B8" "#4C4C4C" "#000000"

Notice that the hex codes corresponding to three coordinates in sRGB space are always thesame, indicating gray colors. Analogously, hex color codes can also be transformed – in thiscase RGB rainbow colors from the base R function rainbow():

Page 38: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

38 colorspace: Manipulating and Assessing Colors and Palettes

1

23

4

5

6 7

8

1

23

4

5

6 7

8

1

23

4

5

6 7

8

1

23

4

5

6 7

8

Figure 32: Color wheels in RGB (left) and HCL (right) space in color (top) and desaturatedgrayscale (bottom).

R> rainbow(3)

[1] "#FF0000FF" "#00FF00FF" "#0000FFFF"

R> desaturate(rainbow(3))

[1] "#7F7F7FFF" "#DCDCDCFF" "#4C4C4CFF"

Already this simple example shows that the three RGB rainbow colors have very differentgrayscale levels. This can be brought even more clearly when using a full color wheel (ofcolors with hues in [0, 360] degrees). While the RGB rainbow() is very unbalanced, theHCL rainbow_hcl() (or also qualitative_hcl()) is (by design) balanced with respect toluminance.

R> wheel <- function(col, radius = 1, ...)+ pie(rep(1, length(col)), col = col, radius = radius, ...)R> par(mar = rep(0.5, 4), mfrow = c(2, 2))R> wheel(rainbow(8))R> wheel(rainbow_hcl(8))R> wheel(desaturate(rainbow(8)))R> wheel(desaturate(rainbow_hcl(8)))

8.2. Lighten or darken colors

In principle, a similar approach for lightening and darkening colors can be employed as fordesaturation above. The colors can simply be transformed to HCL space and then the lumi-nance can either be decreased (turning the color darker) or increased (turning it lighter) while

Page 39: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 39

−40%

−20%

0%

20%

40%

Figure 33: Okabe-Ito palette (0%) along with two levels of both lightening and darkening,respectively.

preserving the hue and chroma coordinates. This strategy typically works well for lighteningcolors, although in some situations the result can be somewhat too colorful. Conversely, whendarkening rather light colors with little chroma, this can result in rather gray colors.In these situations, an alternative might be to apply the analogous strategy in HLS spacewhich is frequently used in HTML style sheets. However, this strategy may also yield colorsthat are either too gray or too colorful. A compromise that sometimes works well is to adjustthe luminance coordinate in HCL space but to take the chroma coordinate corresponding theHLS transformation.We have found that typically the HCL-based transformation performs best for lighteningcolors and this is hence the default in lighten(). For darkening colors, the combined strategyoften works best and is hence the default in darken(). In either case it is recommended totry the other available strategies in case the default yields unexpected results.Regardless of the chosen color space, the adjustment of the L component by a certain amountcan occur by two methods, relative (the default) or absolute. For example for darkening theseeither use L - 100 * amount (absolute) or L * (1 - amount) (relative). See ?lighten and?darken for more details.For illustration the qualitative palette suggested by Okabe and Ito (2008) is transformed bytwo levels of both lightening and darkening, respectively.

R> oi <- c("#61A9D9", "#ADD668", "#E6D152", "#CE6BAF", "#797CBA")R> swatchplot(+ "-40%" = lighten(oi, 0.4),+ "-20%" = lighten(oi, 0.2),+ " 0%" = oi,+ " 20%" = darken(oi, 0.2),+ " 40%" = darken(oi, 0.4),+ off = c(0, 0)+ )

Page 40: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

40 colorspace: Manipulating and Assessing Colors and Palettes

8.3. Maximum chroma for given hue and luminance

As the possible combinations of chroma and luminance in HCL space depend on hue, it isnot obvious which trajectories through HCL space are possible prior to trying a specific HCLcoordinate by calling polarLUV(). To avoid having to fix up the color upon conversion toRGB hex() color codes, the max_chroma() function computes (approximately) the maximumchroma possible. For illustration we show that for given luminance (here: L = 50) themaximum chroma varies substantially with hue:

R> max_chroma(seq(0, 360, by = 60), 50)

[1] 137.96 59.99 69.06 39.81 65.45 119.54 137.96

Similarly, maximum chroma also varies substantially across luminance values for a given hue(here: H = 120, green):

R> max_chroma(120, seq(0, 100, by = 20))

[1] 0.00 28.04 55.35 82.79 110.28 0.00

8.4. Additive mixing of two colors

In additive color models like RGB() or XYZ() it can be useful to combine colors by additivemixing. Below a fully saturated red and green are mixed, yielding a medium brownish yellow.

R> R <- RGB(1, 0, 0)R> G <- RGB(0, 1, 0)R> Y <- mixcolor(0.5, R, G)R> Y

R G B[1,] 0.5 0.5 0

9. Summary and discussionThis manuscript provides an overview of the broad capabilities of the colorspace package forselecting individual colors or color palettes, manipulating these colors, and employing themin various kinds of visualizations.In particular, the package provides various qualitative, sequential, and diverging palettesderived by relatively simple trajectories in HCL (Hue–Chroma–Luminance) space. In contrastto many other packages providing modern balanced color palettes (such as ColorBrewer.org,CARTO, viridis, or scico) special emphasis is given to flexibility of the palettes that can beadjusted to the particular needs of a given data visulization. The manuscript also providesvarious tips and tricks for choosing an effective palette in a given situation. Further usefulguidance is provided in many sources, including: Ware (1988), Okabe and Ito (2008), Aigner

Page 41: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 41

(2010), Stauffer et al. (2015), Zhang (2015), Rost (2018), Wilke (2019), and Ciechanowski(2019), among many others.Further R packages that can complement the palettes provided by colorspace include: Poly-chrome (Coombes and Brock 2018; Coombes, Brock, Abrams, and Abruzzo 2018) implementsstrategies for qualitative palettes with many “categories”. While the qualitative palettes inSection 4 yield only about 6–8 clearly distinguishable colors due to the fixed chroma andluminance, Polychrome relaxes this restriction and can thus find a larger number of colors inCIELUV space that are spaced as far apart as possible. It also has several functions for visual-izing color palettes in different ways. The palette collection packages pals (Wright 2018) andpaletteer (Hvitfeldt 2019) also provide a wide range of prespecified palettes, including somequalitative schemes with many categories. Note that the palettes are quite diverse, though,and not all of them are equally suitable for coding qualitative information. The visualizationfunctions in colorspace from Section 5 may be helpful in assessing their properties. roloc(Murrell 2018b,a) also provides color conversions, but not between numeric colour spaces;instead, from numeric color spaces to English color names.In addition to the R version of colorspace, a Python 2/Python 3 re-implementation is in betaand available at https://github.com/retostauffer/python-colorspace. In the manuscriptwe focus on the more mature R implementation but replication materials for most examplesare not only provided for R but also for Python.

Computational detailsThe results in this paper were obtained using R 3.5.2 (R Core Team 2018) with the packagescolorspace 1.4.1 (Ihaka et al. 2019), ggplot2 3.1.0 (Wickham et al. 2018), RColorBrewer1.1.2 (Neuwirth 2014), rcartocolor 0.0.22 (Nowosad 2018), viridis 0.5.1 (Garnier 2018), scico1.1.0 (Pedersen and Crameri 2018). R itself and all packages used are available from theComprehensive R Archive Network (CRAN) at https://CRAN.R-project.org/.

References

Aigner W (2010). “Perception and Visualization.” URL http://www.ifs.tuwien.ac.at/~silvia/wien/vu-infovis/PDF-Files/02_perception-visualization_1up.pdf.

Brettel H, Viénot F, Mollon JD (1997). “Computerized Simulation of Color Appearance forDichromats.” Journal of the Optical Society of America A, 14, 2647–2655. doi:10.1364/josaa.14.002647.

Brewer CA (1999). “Color Use Guidelines for Data Representation.” In Proceedings of the Sec-tion on Statistical Graphics, American Statistical Association, pp. 55–60. Alexandria, VA.URL http://www.personal.psu.edu/faculty/c/a/cab38/ColorSch/ASApaper.html.

CARTO (2019). “CARTOColors – Data-Driven Color Schemes.” URL https://carto.com/carto-colors/.

Chang W, Cheng J, Allaire JJ, Xie Y, McPherson J (2018). shiny: Web Application Frame-work for R. R package version 1.1.0, URL https://CRAN.R-project.org/package=shiny.

Page 42: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

42 colorspace: Manipulating and Assessing Colors and Palettes

Ciechanowski B (2019). “Color Spaces.” URL https://ciechanow.ski/color-spaces/.

Coombes K, Brock G, Abrams ZB, Abruzzo LV (2018). “Polychrome: Creating and AssessingQualitative Palettes with Many Colors.” bioRxiv 303883. doi:10.1101/303883.

Coombes KR, Brock G (2018). Polychrome: Qualitative Palettes with Many Colors. R packageversion 1.1.1, URL https://CRAN.R-project.org/package=Polychrome.

Crameri F (2018). “Geodynamic Diagnostics, Scientific Visualisation and StagLab 3.0.” Geo-scientific Model Development, 11(6), 2541–2562. doi:10.5194/gmd-11-2541-2018.

Gama J, Davis G (2018). colorscience: Color Science Methods and Data. R package version1.0.5, URL https://CRAN.R-project.org/package=colorscience.

Garnier S (2018). viridis: Default Color Maps from matplotlib. R package version 0.5-1, URLhttps://CRAN.R-project.org/package=viridis.

Harrower MA, Brewer CA (2003). “ColorBrewer.org: An Online Tool for Selecting ColorSchemes for Maps.” The Cartographic Journal, 40, 27–37. URL http://ColorBrewer.org/.

Hawkins E, McNeall D, Stephenson D, Williams J, Carlson D (2014). “The End of theRainbow – An Open Letter to the Climate Science Community.” URL http://www.climate-lab-book.ac.uk/2014/end-of-the-rainbow/.

Hvitfeldt E (2019). paletteer: Comprehensive Collection of Color Palettes. R package version0.2.1, URL https://CRAN.R-project.org/package=paletteer.

Ihaka R (2003). “Colour for Presentation Graphics.” In K Hornik, F Leisch, A Zeileis(eds.), Proceedings of the 3rd International Workshop on Distributed Statistical Computing,Vienna, Austria. ISSN 1609-395X, URL http://www.ci.tuwien.ac.at/Conferences/DSC-2003/Proceedings/.

Ihaka R, Murrell P, Hornik K, Fisher JC, Stauffer R, Wilke CO, McWhite CD, Zeileis A(2019). colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes. R pack-age version 1.4-0, URL https://CRAN.R-project.org/package=colorspace.

Lumley T (2006). “Color Coding and Color Blindness in Statistical Graphics.” ASA Statis-tical Computing & Graphics Newsletter, 17(2), 4–7. URL http://stat-computing.org/newsletter/issues/scgn-17-2.pdf.

Lumley T (2013). dichromat: Color Schemes for Dichromats. R package version 2.0-0, URLhttps://CRAN.R-project.org/package=dichromat.

Machado GM, Oliveira MM, Fernandes LAF (2009). “A Physiologically-Based Model forSimulation of Color Vision Deficiency.” IEEE Transactions on Visualization and ComputerGraphics, 15(6), 1291–1298. doi:10.1109/TVCG.2009.113. URL http://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html.

Murrell P (2018a). “Generating Colour Names: The roloc Package forR.” URL https://stattech.wordpress.fos.auckland.ac.nz/2018/01/25/2018-01-generating-colour-names-the-roloc-package-for-r/.

Page 43: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 43

Murrell P (2018b). roloc: Convert Colour Specification to Colour Name. R package version0.1-1, URL https://CRAN.R-project.org/package=roloc.

Neuwirth E (2014). RColorBrewer: ColorBrewer Palettes. R package version 1.1-2, URLhttps://CRAN.R-project.org/package=RColorBrewer.

Nowosad J (2018). rcartocolor: ‘CARTOColors’ Palettes. R package version 0.0.22, URLhttps://CRAN.R-project.org/package=rcartocolor.

Okabe M, Ito K (2008). “Color Universal Design (CUD): How to Make Figures and Presenta-tions That Are Friendly to Colorblind People.” URL http://jfly.iam.u-tokyo.ac.jp/color/.

Pedersen TL, Crameri F (2018). scico: Colour Palettes Based on the Scientific Colour-Maps.R package version 1.0.0, URL https://CRAN.R-project.org/package=scico.

Pedersen TL, Nicolae B, François R (2018). farver: Vectorised Colour Conversion and Com-parison. R package version 1.1.0, URL https://CRAN.R-project.org/package=farver.

Ram K, Wickham H (2018). wesanderson: A Wes Anderson Palette Generator. R packageversion 0.3.6, URL https://CRAN.R-project.org/package=wesanderson.

R Core Team (2018). R: A Language and Environment for Statistical Computing. R Founda-tion for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.

Rost LC (2018). “What to Consider When Choosing Colors for Data Visualization.” URLhttps://blog.datawrapper.de/colors/.

Smith N, Van der Walt S (2015). “A Better Default Colormap for matplotlib.” In SciPy 2015– Scientific Computing with Python. Austin. URL https://www.youtube.com/watch?v=xAoljeRJ3lU.

Stauffer R, Mayr GJ, Dabernig M, Zeileis A (2015). “Somewhere over the Rainbow: How toMake Effective Use of Colors in Meteorological Visualizations.” Bulletin of the AmericanMeteorological Society, 96(2), 203–216. doi:10.1175/BAMS-D-13-00155.1.

Tufte ER (1990). Envisioning Information. Graphics Press, Cheshire, CT.

Viénot F, Brettel H, Mollon JD (1999). “Digital Video Colourmaps for Checking the Legibilityof Displays by Dichromats.” Color Research and Application, 24(4), 243–252. doi:10.1002/(sici)1520-6378(199908)24:4<243::aid-col5>3.3.co;2-v.

Viénot F, Brettel H, Ott L, M’Barek AB, Mollon JD (1995). “What Do Colour-Blind PeopleSee?” Nature, 376, 127–128. doi:10.1038/376127a0.

Ware C (1988). “Color Sequences for Univariate Maps: Theory, Experiments and Principles.”IEEE Computer Graphics and Applications, 8(5), 41–49. doi:10.1109/38.7760.

Ware C (2004). “Color.” In Information Visualization: Perception for Design, chapter 4, pp.103–149. Morgan Kaufmann Publishers Inc.

Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis. 2nd edition. Springer-Verlag. URL http://ggplot2.org/.

Page 44: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

44 colorspace: Manipulating and Assessing Colors and Palettes

Wickham H, Chang W, Henry L, Pedersen TL, Takahashi K, Wilke C, Woo K (2018). ggplot2:Create Elegant Data Visualisations Using the Grammar of Graphics. R package version3.1.0, URL https://CRAN.R-project.org/package=ggplot2.

Wikipedia (2019a). “CIE 1931 Color Space — Wikipedia, The Free Encyclopedia.” URLhttps://en.wikipedia.org/wiki/CIE_1931_color_space, accessed 2019-01-05.

Wikipedia (2019b). “CIELAB Color Space — Wikipedia, The Free Encyclopedia.” URLhttps://en.wikipedia.org/wiki/CIELAB_color_space, accessed 2019-01-05.

Wikipedia (2019c). “CIELUV — Wikipedia, The Free Encyclopedia.” URL https://en.wikipedia.org/wiki/CIELUV, accessed 2019-01-05.

Wikipedia (2019d). “Color Space — Wikipedia, The Free Encyclopedia.” URL https://en.wikipedia.org/wiki/Color_space, accessed 2019-03-11.

Wikipedia (2019e). “HCL Color Space — Wikipedia, The Free Encyclopedia.” URL https://en.wikipedia.org/wiki/HCL_color_space, accessed 2019-03-11.

Wikipedia (2019f). “HSL and HSV — Wikipedia, The Free Encyclopedia.” URL https://en.wikipedia.org/wiki/HSL_and_HSV, accessed 2019-01-05.

Wikipedia (2019g). “RGB Color Space — Wikipedia, The Free Encyclopedia.” URL https://en.wikipedia.org/wiki/RGB_color_space, accessed 2019-01-05.

Wikipedia (2019h). “sRGB — Wikipedia, The Free Encyclopedia.” URL https://en.wikipedia.org/wiki/sRGB, accessed 2019-01-05.

Wikipedia (2019i). “Web Colors — Wikipedia, The Free Encyclopedia.” URL https://en.wikipedia.org/wiki/Web_colors, accessed 2019-03-11.

Wilke CO (2019). Fundamentals of Data Visualization. O’Reilly Media. URL https://serialmentor.com/dataviz/color-basics.html.

Wilkinson L (2005). The Grammar of Graphics. 2nd edition. Springer-Verlag.

Wright K (2018). pals: Color Palettes, Colormaps, and Tools to Evaluate Them. R packageversion 1.5, URL https://CRAN.R-project.org/package=pals.

Zeileis A, Gaslam B, Murrell P, Pedersen TL (2018). “Benchmarking Color SpaceConversions.” Twitter discussion, URL https://twitter.com/AchimZeileis/status/1076228936810590208.

Zeileis A, Hornik K, Murrell P (2009). “Escaping RGBland: Selecting Colors for StatisticalGraphics.” Computational Statistics & Data Analysis, 53, 3259–3270. doi:10.1016/j.csda.2008.11.033.

Zhang S (2015). “Finding the Right Color Palettes forData Visualizations.” URL https://blog.graphiq.com/finding-the-right-color-palettes-for-data-visualizations-fcd4e707a283.

Page 45: colorspace: AToolboxforManipulatingand ... · Figure 6: Palette visualization and assessment for sequential_hcl(4, "Purples 3") palette. Left: Demo heatmap. Center: Chroma-luminance

Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke 45

Affiliation:Achim ZeileisUniversität InnsbruckDepartment of StatisticsFaculty of Economics and StatisticsUniversitätsstr. 156020 Innsbruck, AustriaE-mail: [email protected]: https://eeecon.uibk.ac.at/~zeileis/