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:
install.packages("viridis")
library(viridis)
For base plots, use the viridis()
function to generate a palette:
x <- y <- seq(-8*pi, 8*pi, len = 40)
r <- sqrt(outer(x^2, y^2, "+"))
filled.contour(cos(r^2)*exp(-r/(2*pi)),
axes=FALSE,
color.palette=viridis,
asp=1)
For ggplot, use scale_color_viridis() and scale_fill_viridis():
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 R
ecosystem. viridis
provides additional functionalities, in particular bindings for ggplot2
.
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”.