Colorbrewer and viridis have been the two main resources for this page.

library(RColorBrewer)
display.brewer.all(colorblindFriendly = TRUE)

Continuous (sequential)

Please see the viridis: Default Color Maps from ‘matplotlib’ CRAN package. Thre is a great vignette by the package authors.

library(ggplot2)
library(viridis)

ggplot(data.frame(x = rnorm(10000), y = rnorm(10000)), aes(x = x, y = y)) +
    geom_hex() +
    coord_fixed() +
    scale_fill_viridis() + # The virdis color scale
    theme_bw()
## Warning: Computation failed in `stat_binhex()`:
## Package `hexbin` required for `stat_binhex`.
## Please install and try again.

Decile color palette

library(scales)
show_col(viridis_pal(option = 'viridis')(10))

show_col(viridis_pal(option = 'magma')(10))

Divergent

Here’s a function to plot colors in a series of rectangles (written by Vicki)

pal <- function(col, border = "light gray", ...) {
    n <- length(col)
    plot(0, 0,
         type = "n",
         xlim = c(0, 1),
         ylim = c(0, 1),
         axes = FALSE,
         xlab = "", ylab = "", ...)
    rect(0:(n - 1) / n,
         0,
         1:n/n,
         1,
         col = col,
         border = border)
}

HEX

#b2182b
#ef8a62
#fddbc7
#d1e5f0
#67a9cf
#2166ac
colours <- c(
    '#b2182b',
    '#ef8a62',
    '#fddbc7',
    '#d1e5f0',
    '#67a9cf',
    '#2166ac'
)
pal(colours)

colours <- c(
    '#b2182b',
    '#ef8a62',
    '#fddbc7',
    '#ffffff',
    '#d1e5f0',
    '#67a9cf',
    '#2166ac'
)
pal(colours)

Categorical (qualiative)

Here is a function to plot colors in a pie chart (written by Vicki)

wheel <- function(col, radius = 1, ...) {
    pie(rep(1, length(col)), col = col, radius = radius, ...)
}

Colorblind and Print friendly

Colorbrewer only has 1 color scheme that is both colorblind and print friendly. It only allows 4 classes.

Hex:

#a6cee3
#1f78b4
#b2df8a
#33a02c
cbPalette <- c(
    '#a6cee3',
    '#1f78b4',
    '#b2df8a',
    '#33a02c'
)

wheel(cbPalette)

Here we added a grey color to be used as a NA value in plots.

cbPalette <- c(
    '#a6cee3',
    '#1f78b4',
    '#b2df8a',
    '#33a02c',
    "#999999",
    '#000000',
    '#ffffff'
)

wheel(cbPalette)

RGB:

166,206,227
31,120,180
178,223,138
51,160,44

CMTK

35,7,0,0
90,30,0,0
30,0,45,0
80,0,100,0

Colorblind friendly

The colorbline friendly pallete is the same as the colorblind and print friendly color scheme.