Use the color scales in this package to make plots that are pretty, better represent your data, easier to read by those with colorblindness, and print well in gray scale.
Install viridis like any R package:
For base plots, use the
viridis() function to generate a palette:
<- y <- seq(-8*pi, 8*pi, len = 40) x <- sqrt(outer(x^2, y^2, "+")) r filled.contour(cos(r^2)*exp(-r/(2*pi)), axes=FALSE, color.palette=viridis, asp=1)
For ggplot, use
library(ggplot2) ggplot(data.frame(x = rnorm(10000), y = rnorm(10000)), aes(x = x, y = y)) + geom_hex() + coord_fixed() + scale_fill_viridis() + theme_bw()
viridis, and its companion package
viridisLite provide a series of color maps that are designed to improve graph readability for readers with common forms of color blindness and/or color vision deficiency. The color maps are also perceptually-uniform, both in regular form and also when converted to black-and-white for printing.
These color maps are designed to be:
viridisLite provides the base functions for generating the color maps in base
R. The package is meant to be as lightweight and dependency-free as possible for maximum compatibility with all the
viridis provides additional functionalities, in particular bindings for
The package contains eight color scales: “viridis”, the primary choice, and five alternatives with similar properties - “magma”, “plasma”, “inferno”, “civids”, “mako”, and “rocket” -, and a rainbow color map - “turbo”.
The color maps
plasma were created by Stéfan van der Walt ([@stefanv](https://github.com/stefanv)) and Nathaniel Smith ([@njsmith](https://github.com/njsmith)). If you want to know more about the science behind the creation of these color maps, you can watch this presentation of
viridis by their authors at SciPy 2015.
The color map
cividis is a corrected version of ‘viridis’, developed by Jamie R. Nuñez, Christopher R. Anderton, and Ryan S. Renslow, and originally ported to
R by Marco Sciaini ([@msciain](https://github.com/marcosci)). More info about
cividis can be found in this paper.
The color maps
rocket were originally created for the
Seaborn statistical data visualization package for Python. More info about
rocket can be found on the
The color map
turbo was developed by Anton Mikhailov to address the shortcomings of the Jet rainbow color map such as false detail, banding and color blindness ambiguity. More infor about
turbo can be found here.
Let’s compare the viridis and magma scales against these other commonly used sequential color palettes in R:
It is immediately clear that the “rainbow” palette is not perceptually uniform; there are several “kinks” where the apparent color changes quickly over a short range of values. This is also true, though less so, for the “heat” colors. The other scales are more perceptually uniform, but “viridis” stands out for its large perceptual range. It makes as much use of the available color space as possible while maintaining uniformity.
Now, let’s compare these as they might appear under various forms of colorblindness, which can be simulated using the dichromat package: