R Language Color schemes for graphics viridis - print and colorblind friendly palettes


Example

Viridis (named after the chromis viridis fish) is a recently developed color scheme for the Python library matplotlib (the video presentation by the link explains how the color scheme was developed and what are its main advantages). It is seamlessly ported to R.

There are 4 variants of color schemes: magma, plasma, inferno, and viridis (default). They are chosen with the option parameter and are coded as A, B, C, and D, correspondingly. To have an impression of the 4 color schemes, look at the maps:

enter image description here (image souce)


The package can be installed from CRAN or github.


The vignette for viridis package is just brilliant.


Nice feature of the viridis color scheme is integration with ggplot2. Within the package two ggplot2-specific functions are defined: scale_color_viridis() and scale_fill_viridis(). See the example below:

library(viridis)
library(ggplot2)

gg1 <- ggplot(mtcars)+
    geom_point(aes(x = mpg, y = hp, color = disp), size = 3)+
    scale_color_viridis(option = "B")+
    theme_minimal()+
    theme(legend.position = c(.8,.8))

gg2 <- ggplot(mtcars)+
        geom_violin(aes(x = factor(cyl), y = hp, fill = factor(cyl)))+
        scale_fill_viridis(discrete = T)+
        theme_minimal()+
        theme(legend.position = 'none')

library(cowplot)
output <- plot_grid(gg1,gg2, labels = c('B','D'),label_size = 20)
print(output)

enter image description here