A Toolbox for Manipulating and Assessing Color Palettes for Statistical Graphics
Achim Zeileis, Jason C. Fisher, Kurt Hornik, Ross Ihaka, Claire D. McWhite, Paul Murrell, Reto Stauffer, Claus O. Wilke http://colorspace.R-Forge.R-project.org/ Color spaces
Origin of the package: Convert colors between various three-dimensional representations of color. In particular: From the perceptually-based HCL (Hue-Chroma-Luminance) to standard Red-Green-Blue (sRGB, and corresponding hex codes) space.
polarLUV LUV HSV (= HCL)
white point gamma = D65 (= 2.4) XYZ RGB sRGB hex
polarLAB LAB HLS
1/18 RGB: Motivated by how comput- ers/TVs used to generate and still rep- resent color.
Red
Green
Blue
HCL vs. RGB
HCL: Polar coordinates in CIELUV. Captures perceptual dimensions of the human visual system very well.
Hue (Type of color)
Chroma (Colorfulness)
Luminance (Brightness)
2/18 HCL vs. RGB
HCL: Polar coordinates in CIELUV. RGB: Motivated by how comput- Captures perceptual dimensions of ers/TVs used to generate and still rep- the human visual system very well. resent color.
Hue Red (Type of color)
Chroma Green (Colorfulness)
Luminance Blue (Brightness)
2/18 RGB Spectrum 1.0 Red Green Blue 0.8 0.6 0 0.4 Red / Green Blue 0.2 0.0
Index 150 100 360 0 Hue 0 50 Chroma / Luminance Hue Chroma Luminance 0
HCL Spectrum −360
HCL vs. RGB: The End of the Rainbow
RGB Spectrum 1.0 Red Green Blue 0.8 0.6 0 0.4 Red / Green Blue 0.2 0.0
100 Index 360 80 270 60 0 180 Hue 40 90 Chroma / Luminance 20 Hue Chroma Luminance 0 0 HCL Spectrum
3/18 HCL vs. RGB: The End of the Rainbow
RGB Spectrum RGB Spectrum 1.0 1.0 Red Green Blue Red Green Blue 0.8 0.8 0.6 0.6 0 0 0.4 0.4 Red / Green Blue Red / Green Blue 0.2 0.2 0.0 0.0
100 Index 360 Index 150 80 270 60 100 360 0 0 180 Hue Hue 40 0 50 90 Chroma / Luminance Chroma / Luminance 20 Hue Chroma Luminance Hue Chroma Luminance 0 0 0
HCL Spectrum HCL Spectrum −360
3/18 Qualitative: For categorical information, i.e., where no particular ordering of categories is available. Function: qualitative_hcl().
Sequential: For ordered/numeric information, i.e., where colors go from high to low (or vice versa). Function: sequential_hcl().
Diverging: For ordered/numeric information around a central neutral value, i.e., where colors diverge from neutral to two extremes. Function: diverging_hcl().
Color palettes: Somewhere over the Rainbow
Qualitative (Set 2) Sequential (Blues 3) Diverging (Green−Brown)
Color Color Color
Desaturated Desaturated Desaturated
4/18 Sequential: For ordered/numeric information, i.e., where colors go from high to low (or vice versa). Function: sequential_hcl().
Diverging: For ordered/numeric information around a central neutral value, i.e., where colors diverge from neutral to two extremes. Function: diverging_hcl().
Color palettes: Somewhere over the Rainbow
Qualitative (Set 2) Sequential (Blues 3) Diverging (Green−Brown)
Color Color Color
Desaturated Desaturated Desaturated
Qualitative: For categorical information, i.e., where no particular ordering of categories is available. Function: qualitative_hcl().
4/18 Diverging: For ordered/numeric information around a central neutral value, i.e., where colors diverge from neutral to two extremes. Function: diverging_hcl().
Color palettes: Somewhere over the Rainbow
Qualitative (Set 2) Sequential (Blues 3) Diverging (Green−Brown)
Color Color Color
Desaturated Desaturated Desaturated
Qualitative: For categorical information, i.e., where no particular ordering of categories is available. Function: qualitative_hcl().
Sequential: For ordered/numeric information, i.e., where colors go from high to low (or vice versa). Function: sequential_hcl().
4/18 Color palettes: Somewhere over the Rainbow
Qualitative (Set 2) Sequential (Blues 3) Diverging (Green−Brown)
Color Color Color
Desaturated Desaturated Desaturated
Qualitative: For categorical information, i.e., where no particular ordering of categories is available. Function: qualitative_hcl().
Sequential: For ordered/numeric information, i.e., where colors go from high to low (or vice versa). Function: sequential_hcl().
Diverging: For ordered/numeric information around a central neutral value, i.e., where colors diverge from neutral to two extremes. Function: diverging_hcl().
4/18 Color palettes: Somewhere over the Rainbow
Sequential: Luminance contrast is crucial (dark to light or vice versa).
Blues 2
Blues 3
Blues
5/18 Color palettes: Somewhere over the Rainbow
Blues 2: Single hue. Decreasing chroma with increasing luminance.
Blues 2 100 360
Blues 3 80 270
Blues 60 0 180 Hue 40 Chroma / Luminance 90 20
Hue Chroma Luminance 0 0 HCL Spectrum 5/18 Color palettes: Somewhere over the Rainbow
Blues 3: Single hue. Triangular chroma to achieve higher luminance contrast.
Blues 2 100 360
Blues 3 80 270
Blues 60 0 180 Hue 40 Chroma / Luminance 90 20
Hue Chroma Luminance 0 0 HCL Spectrum 5/18 Color palettes: Somewhere over the Rainbow
Blues: Multi hue. Triangular chroma. High luminance contrast.
Blues 2 100 360
Blues 3 80 270
Blues 60 0 180 Hue 40 Chroma / Luminance 90 20
Hue Chroma Luminance 0 0 HCL Spectrum 5/18 100 360 80 270 60 0 180 Hue 40 Chroma / Luminance 90 20
Hue Chroma Luminance 0 0 HCL Spectrum
Color palettes: Somewhere over the Rainbow
Diverging: Combine two sequential palettes with balanced chroma/luminance. 100 360 80 270 60 0 180 Hue 40 Chroma / Luminance 90 20
Hue Chroma Luminance 0 0 HCL Spectrum 6/18 Color palettes: Somewhere over the Rainbow
Diverging: Combine two sequential palettes with balanced chroma/luminance. 100 360 100 360 80 80 270 270 60 60 0 0 180 180 Hue Hue 40 40 Chroma / Luminance Chroma / Luminance 90 90 20 20
Hue Chroma Luminance Hue Chroma Luminance 0 0 0 0 HCL Spectrum HCL Spectrum 6/18 Color palettes: Somewhere over the Rainbow
R> hcl_palettes(plot = TRUE)
Qualitative Greens 3 BluGrn YlOrBr Blue−Red 2
Pastel 1 Oslo Teal OrRd Blue−Red 3
Dark 2 Sequential (multi−hue) TealGrn Oranges Red−Green
Dark 3 Purple−Blue Emrld YlGn Purple−Green
Set 2 Red−Purple BluYl YlGnBu Purple−Brown
Set 3 Red−Blue ag_GrnYl Reds Green−Brown
Warm Purple−Orange Peach RdPu Blue−Yellow 2
Cold Purple−Yellow PinkYl PuRd Blue−Yellow 3
Harmonic Blue−Yellow Burg Purples Green−Orange
Dynamic Green−Yellow BurgYl PuBuGn Cyan−Magenta
Sequential (single−hue) Red−Yellow RedOr PuBu Tropic
Grays Heat OrYel Greens Broc
Light Grays Heat 2 Purp BuGn Cork
Blues 2 Terrain PurpOr GnBu Vik
Blues 3 Terrain 2 Sunset BuPu Berlin
Purples 2 Viridis Magenta Blues Lisbon
Purples 3 Plasma SunsetDark Lajolla Tofino
Reds 2 Inferno ag_Sunset Turku
Reds 3 Dark Mint BrwnYl Diverging
Greens 2 Mint YlOrRd Blue−Red 7/18 Statistical graphics
Base: • HCL palette functions return hex color vector. • Typically passed to col = argument of base plotting functions. ggplot2: • Scales of type scale_
8/18 Statistical graphics: Base
R> q4 <- qualitative_hcl(4, palette = "Dark 3") R> plot(log(EuStockMarkets), plot.type = "single", col = q4, lwd = 2) R> legend("topleft", colnames(EuStockMarkets), col = q4, lwd = 3, bty = "n")
DAX 9.0 SMI CAC FTSE 8.5 8.0 log(EuStockMarkets) 7.5
1992 1993 1994 1995 1996 1997 1998
Time 9/18 Statistical graphics: ggplot2
R> library("ggplot2") R> ggplot(iris, aes(x = Sepal.Length, fill = Species)) + geom_density(alpha = 0.6) + + scale_fill_discrete_qualitative(palette = "Dark 3")
1.2
0.8 Species
setosa versicolor density virginica
0.4
0.0
5 6 7 8 Sepal.Length 10/18 Emulation: Color vision deficiency. • deutan(): Deuteranopia (green deficient). • protan(): Protanopia (red deficient). • tritan(): Tritanopia (blue deficient).
Visualization and assessment
Visualizations: Based on vector of colors. • 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.
11/18 Visualization and assessment
Visualizations: Based on vector of colors. • 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.
Emulation: Color vision deficiency. • deutan(): Deuteranopia (green deficient). • protan(): Protanopia (red deficient). • tritan(): Tritanopia (blue deficient).
11/18 Visualization and assessment: demoplot()
R> cl <- sequential_hcl(5, palette = "Heat") R> demoplot(cl, type = "...")
map heatmap scatter spine bar
● ● ●● ● ●● ● ● ● ●● ● ●●●●● ● ●●● ● ●●●●●●● ● ● ●●●● ●●●●● ● ● ●● ●● ● ● ●● ● ● ●●● ●●●●●● ● ● ● ●●●● ●●● ●● ●●●●●●●● ● ●●● ● ● ● ●●●● ●●● ●●●● ● ● ● ●● ●● ●●● ●●●●●●●●●●●●●●●● ●●● ●● ●●●●●● ●●●●●● ●●●●●● ● ● ●●●●●● ●●●●●● ●● ● ●●●●●●●●● ●● ●●●● ● ● ●●●●● ● ●● ● ● ● ●●● ● ● ● ●●●● ●● ●● ●● ●●●●●● ● ●● ● ● ● ● ●● ●●●●●●●●●● ● ● ●●● ● ● ●●● ●●● ● ● ● ●●●● ●●●● ● ●●● ●●●●● ●● ● ●●●●●● ● ● ●●● ● ● ● ●●● ●● ●●●●●●●● ● ● ● ●● ●●● ●●● ● ●●●● ● ●●●●●●●●●● ●● ●● ● ●● ●● ●●● ● ● ● ●●● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●
pie perspective mosaic lines
12/18 Viridis 100 360 80 270 60 0 180 Hue 40 Chroma / Luminance 90 20
Hue Chroma Luminance 0 0 HCL Spectrum
Approximations of other palettes
ColorBrewer.org: YlGnBu 100 360 80 270 60 0 180 Hue 40 Chroma / Luminance 90 20
Hue Chroma Luminance 0 0 HCL Spectrum
13/18 Approximations of other palettes
ColorBrewer.org: YlGnBu Viridis 100 360 100 360 80 80 270 270 60 60 0 0 180 180 Hue Hue 40 40 Chroma / Luminance Chroma / Luminance 90 90 20 20
Hue Chroma Luminance Hue Chroma Luminance 0 0 0 0 HCL Spectrum HCL Spectrum
13/18 Color apps
Facilitate exploration: Graphical user interfaces as shiny apps. • Palette constructor: choose_palette() or hclwizard() (also in tcltk). • Color picker: choose_color() or hcl_color_picker(). • Color vision deficiency emulator: cvd_emulator().
Online versions: http://hclwizard.org/
14/18 Color apps: choose_palette() / hclwizard()
15/18 Color apps: choose_color() / hcl_color_picker()
16/18 Color apps: cvd_emulator()
17/18 References
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. http://colorspace.R-Forge.R-project.org/
Zeileis A, Hornik K, Murrell P (2009). “Escaping RGBland: Selecting Colors for Statistical Graphics.” Computational Statistics & Data Analysis, 53, 3259–3270. doi:10.1016/j.csda.2008.11.033.
Stauffer R, Mayr GJ, Dabernig M, Zeileis A (2015). “Somewhere over the Rainbow: How to Make Effective Use of Colors in Meteorological Visualizations.” Bulletin of the American Meteorological Society, 96(2), 203–216. doi:10.1175/BAMS-D-13-00155.1
18/18