To help you choose appropriate colours and make using them in {ggplot2} easier
🎨 Working with colours in {ggplot2}
🎨 Choosing effective, accessible colours
🎨 Creating custom colour scales
🎨 Some additional resources
See {paletteer} for a collection of colour palette scales.
Hex code: "#D35269"
RGB value: rgb()
Colour names: colors()
There 657 recognised colour names in R!
Brand guidelines
Images
Cara Thompson (R-Ladies Cambridge): www.cararthompson.com/talks/rl-cambridge-beautifully-annotated
name n tolerance ncp ndcp min_dist mean_dist max_dist
1 normal 3 28.4883 3 3 28.48830 30.44199 33.74932
2 deuteranopia 3 28.4883 3 2 26.17337 35.31761 42.21131
3 protanopia 3 28.4883 3 1 25.58046 27.82692 29.85853
4 tritanopia 3 28.4883 3 3 32.22092 34.99349 36.84926
Minimise the number of colours (no more than 8)
Vary the luminosity of the colours
Check palettes for different chart types: {plotcolr}
Don’t rely on colour: {ggpattern}
…so let’s make a function!
First, let’s define our colours in a list:
my_palettes = function(palette_name,
n,
type = c("discrete", "continuous")) {
palette = my_colours[[palette_name]]
if (missing(n)) {
n = length(palette)
}
type = match.arg(type)
out = switch(type,
continuous = grDevices::colorRampPalette(palette)(n),
discrete = palette[1:n]
)
structure(out, palette_name = palette_name, class = "palette")
}
Discrete scales
Continuous scales
Define a print()
method: adv-r.hadley.nz/s3
Make an R package: r-pkgs.org
Make some matching theme functions: bookdown.org/rdpeng/RProgDA/building-a-new-theme
Slides: nrennie.rbind.io/talks/rladies-cambridge-ggplot2-colours