This function creates a vector of
n equally spaced colors along the
Matplolib 'viridis' color map created by St<c3><a9>fan van der Walt
and Nathaniel Smith. This color map is
designed in such a way that it will analytically be perfectly perceptually-uniform,
both in regular form and also when converted to black-and-white. It is also
designed to be perceived by readers with the most common form of color blindness.
1 2 3 4 5 6 7 8 9 10 11 12
viridis(n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D") viridisMap(n = 256, alpha = 1, begin = 0, end = 1, direction = 1, option = "D") magma(n, alpha = 1, begin = 0, end = 1, direction = 1) inferno(n, alpha = 1, begin = 0, end = 1, direction = 1) plasma(n, alpha = 1, begin = 0, end = 1, direction = 1) cividis(n, alpha = 1, begin = 0, end = 1, direction = 1)
The number of colors (≥ 1) to be in the palette.
The alpha transparency, a number in [0,1], see argument alpha in
The (corrected) hue in [0,1] at which the viridis colormap begins.
The (corrected) hue in [0,1] at which the viridis colormap ends.
Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed.
A character string indicating the colormap option to use. Four options are available: "magma" (or "A"), "inferno" (or "B"), "plasma" (or "C"), "viridis" (or "D", the default option) and "cividis" (or "E").
A corrected version of 'viridis', 'cividis', was developed by Jamie R. Nu<c3><b1>ez and Sean M. Colby. It is optimal for viewing by those with color vision deficiency. 'cividis' is designed to be perfectly perceptually-uniform, both in regular form and also when converted to black-and-white, and can be perceived by readers with all forms of color blindness.
Here are the color scales:
convenience functions for the other colormap options, which are useful the
scale must be passed as a function name.
Semi-transparent colors (0 < alpha < 1) are supported only on some
viridis returns a character vector,
cv, of color hex
codes. This can be used either to create a user-defined color palette for
subsequent graphics by
col = specification in
graphics functions or in
viridisMap returns a
n lines data frame containing the
R), green (
G), blue (
B) and alpha (
n equally spaced colors along the 'viridis' color map.
n = 256 by default, which corresponds to the data from the original
'viridis' color map in Matplotlib.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
library(ggplot2) library(hexbin) dat <- data.frame(x = rnorm(10000), y = rnorm(10000)) ggplot(dat, aes(x = x, y = y)) + geom_hex() + coord_fixed() + scale_fill_gradientn(colours = viridis(256, option = "D")) # using code from RColorBrewer to demo the palette n = 200 image( 1:n, 1, as.matrix(1:n), col = viridis(n, option = "D"), xlab = "viridis n", ylab = "", xaxt = "n", yaxt = "n", bty = "n" )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.