colour

10 November 2021

packages

library(ggplot2)
library(dichromat)
## palettes etc.
library(viridis)
library(cividis) ## https://github.com/marcosci/cividis
library(colorspace)
library(RColorBrewer)
library(cowplot)
library(colorBlindness)

use of colour

colour specification in R

head(colours())

## [1] "white"         "aliceblue"     "antiquewhite"  "antiquewhite1"
## [5] "antiquewhite2" "antiquewhite3"

fade via transparency gradient

dd <- data.frame(x=1:9)
ggplot(dd,aes(x=x,y=1,alpha=x)) +
    geom_point(size=10,colour="red") +
    coord_fixed(ratio=5)+theme_void()

fade via colour gradient

ggplot(dd,aes(x=x,y=1))+
  geom_point(size=10,aes(colour=x))+
  scale_colour_gradient(low="lightgray",high="red")+
  coord_fixed(ratio=5)+theme_void()

saturation

display.brewer.all()

colour spaces

Zeileis, Hornik, and Murrell (2009) Fig 1

Old Faithful data (duration vs waiting time)

HSV, grayscale, HSV heat, HCL heat

Zeileis, Hornik, and Murrell (2009) Fig 3

(left) hue varies, constant saturation & value; (right) hue varies, constant chroma & luminance

Zeileis et al. (2019) Fig 7

CIELAB space

By Holger kkk Everding - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=38366968

Zeileis, Hornik, and Murrell (2009) Fig 4

Zeileis, Hornik, and Murrell (2009) Fig 7

colorspace palettes

png("pix/colorspace.png")
hcl_palettes(plot=TRUE)
dev.off()

colorspace palettes

colorspace demos

png("pix/colordemo.png")
par(mfrow = c(3, 3), mar = c(1,1,1,1))
cl <- sequential_hcl(5, "Heat")
for (i in c("map", "heatmap", "scatter", "spine",
            "bar", "pie", "perspective", "mosaic", "lines")) {
  demoplot(cl, type = i)
}
dev.off()

colorspace demos

I Want Hue

Why stick to a single path in the colour space? Why not fill an area?

demo

hues, randomcoloR (randomColor() !)

colourblind-friendliness

viridis vs. cividis

illustrate dichromat package

par(mfrow=c(2,2),mar=c(1,1,1,1))
p <- brewer.pal("Set1",n=6)
pie(rep(1,6), col=p,main="ColourBrewer Set1")
pie(rep(1,6), col = dichromat(p))
p2 <- brewer.pal("Dark2",n=6)
pie(rep(1,6), col=p2, main="ColourBrewer Dark2")
pie(rep(1,6), col = dichromat(p2))

more packages

colorBlindness::displayAvailablePalette(color="white")

online

upload an image or point to a URL

contrast illusions

Colour appearance depends on neighbours

(Wikipedia)

cultural expectations


(ggplot(dd,aes(x=x,y=1,colour=factor(x)))
  + geom_point(size=10)
  +  coord_fixed(ratio=5)
  + theme(legend.position="none")
  +   scale_colour_manual(values=topo.colors(9))
  + theme_void()
  + theme(legend.position="none")
)

more on available stuff …

library(ggplot2); library(colorspace); library(viridis)
length(apropos("scale_colour_"))

## [1] 36

references

Zeileis, Achim, Jason C. Fisher, Kurt Hornik, Ross Ihaka, Claire D. McWhite, Paul Murrell, Reto Stauffer, and Claus O. Wilke. 2019. “Colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.” arXiv:1903.06490, March. http://arxiv.org/abs/1903.06490.

Zeileis, Achim, Kurt Hornik, and Paul Murrell. 2009. “Escaping RGBland: Selecting Colors for Statistical Graphics.” Computational Statistics & Data Analysis 53 (9): 3259–70. https://doi.org/10.1016/j.csda.2008.11.033.