Title: | Colorblind-Friendly Color Maps for R |
---|---|
Description: | Color maps 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. This package also contains 'ggplot2' bindings for discrete and continuous color and fill scales. A lean version of the package called 'viridisLite' that does not include the 'ggplot2' bindings can be found at <https://cran.r-project.org/package=viridisLite>. |
Authors: | Simon Garnier [aut, cre], Noam Ross [ctb, cph], Bob Rudis [ctb, cph], Marco Sciaini [ctb, cph], Antônio Pedro Camargo [ctb, cph], Cédric Scherer [ctb, cph] |
Maintainer: | Simon Garnier <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.6.5 |
Built: | 2024-10-24 03:59:28 UTC |
Source: | https://github.com/sjmgarnier/viridis |
Scale functions (fill and colour/color) for
ggplot2
.
For discrete == FALSE
(the default) all other arguments are as to
scale_fill_gradientn
or
scale_color_gradientn
. Otherwise the function will
return a discrete_scale
with the plot-computed number
of colors.
See viridis
and
viridis.map
for more information on the color
palettes.
scale_fill_viridis( ..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D", aesthetics = "fill" ) scale_color_viridis( ..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D", aesthetics = "color" ) scale_colour_viridis( ..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D", aesthetics = "color" )
scale_fill_viridis( ..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D", aesthetics = "fill" ) scale_color_viridis( ..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D", aesthetics = "color" ) scale_colour_viridis( ..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D", aesthetics = "color" )
... |
Parameters to |
alpha |
The alpha transparency, a number in [0,1], see argument alpha in
|
begin |
The (corrected) hue in [0,1] at which the color map begins. |
end |
The (corrected) hue in [0,1] at which the color map ends. |
direction |
Sets the order of colors in the scale. If 1, the default,
colors are as output by |
discrete |
Generate a discrete palette? (default: |
option |
A character string indicating the color map option to use. Eight options are available:
|
aesthetics |
Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with. This can be useful, for example, to apply colour settings to the colour and fill aesthetics at the same time, via aesthetics = c("colour", "fill"). |
Noam Ross [email protected]
Bob Rudis [email protected]
Simon Garnier: [email protected]
library(ggplot2) # Ripped from the pages of ggplot2 p <- ggplot(mtcars, aes(wt, mpg)) p + geom_point(size = 4, aes(colour = factor(cyl))) + scale_color_viridis(discrete = TRUE) + theme_bw() # Ripped from the pages of ggplot2 dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6) dsub$diff <- with(dsub, sqrt(abs(x - y)) * sign(x - y)) d <- ggplot(dsub, aes(x, y, colour = diff)) + geom_point() d + scale_color_viridis() + theme_bw() # From the main viridis example dat <- data.frame(x = rnorm(10000), y = rnorm(10000)) ggplot(dat, aes(x = x, y = y)) + geom_hex() + coord_fixed() + scale_fill_viridis() + theme_bw() library(ggplot2) library(MASS) library(gridExtra) data("geyser", package="MASS") ggplot(geyser, aes(x = duration, y = waiting)) + xlim(0.5, 6) + ylim(40, 110) + stat_density2d(aes(fill = ..level..), geom = "polygon") + theme_bw() + theme(panel.grid = element_blank()) -> gg grid.arrange( gg + scale_fill_viridis(option = "A") + labs(x = "Viridis A", y = NULL), gg + scale_fill_viridis(option = "B") + labs(x = "Viridis B", y = NULL), gg + scale_fill_viridis(option = "C") + labs(x = "Viridis C", y = NULL), gg + scale_fill_viridis(option = "D") + labs(x = "Viridis D", y = NULL), gg + scale_fill_viridis(option = "E") + labs(x = "Viridis E", y = NULL), gg + scale_fill_viridis(option = "F") + labs(x = "Viridis F", y = NULL), gg + scale_fill_viridis(option = "G") + labs(x = "Viridis G", y = NULL), gg + scale_fill_viridis(option = "H") + labs(x = "Viridis H", y = NULL), ncol = 4, nrow = 2 )
library(ggplot2) # Ripped from the pages of ggplot2 p <- ggplot(mtcars, aes(wt, mpg)) p + geom_point(size = 4, aes(colour = factor(cyl))) + scale_color_viridis(discrete = TRUE) + theme_bw() # Ripped from the pages of ggplot2 dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6) dsub$diff <- with(dsub, sqrt(abs(x - y)) * sign(x - y)) d <- ggplot(dsub, aes(x, y, colour = diff)) + geom_point() d + scale_color_viridis() + theme_bw() # From the main viridis example dat <- data.frame(x = rnorm(10000), y = rnorm(10000)) ggplot(dat, aes(x = x, y = y)) + geom_hex() + coord_fixed() + scale_fill_viridis() + theme_bw() library(ggplot2) library(MASS) library(gridExtra) data("geyser", package="MASS") ggplot(geyser, aes(x = duration, y = waiting)) + xlim(0.5, 6) + ylim(40, 110) + stat_density2d(aes(fill = ..level..), geom = "polygon") + theme_bw() + theme(panel.grid = element_blank()) -> gg grid.arrange( gg + scale_fill_viridis(option = "A") + labs(x = "Viridis A", y = NULL), gg + scale_fill_viridis(option = "B") + labs(x = "Viridis B", y = NULL), gg + scale_fill_viridis(option = "C") + labs(x = "Viridis C", y = NULL), gg + scale_fill_viridis(option = "D") + labs(x = "Viridis D", y = NULL), gg + scale_fill_viridis(option = "E") + labs(x = "Viridis E", y = NULL), gg + scale_fill_viridis(option = "F") + labs(x = "Viridis F", y = NULL), gg + scale_fill_viridis(option = "G") + labs(x = "Viridis G", y = NULL), gg + scale_fill_viridis(option = "H") + labs(x = "Viridis H", y = NULL), ncol = 4, nrow = 2 )
A data set containing the 2009 unemployment data in the USA by county.
unemp
unemp
A data frame with 3218 rows and 8 variables:
the county ID number
the state FIPS number
the county FIPS number
the county name
the year
the unemployment rate
the county abbreviated name
the state acronym
http://datasets.flowingdata.com/unemployment09.csv
A wrapper function around viridis
to
turn it into a palette function compatible with
discrete_scale
.
viridis_pal(alpha = 1, begin = 0, end = 1, direction = 1, option = "D")
viridis_pal(alpha = 1, begin = 0, end = 1, direction = 1, option = "D")
alpha |
The alpha transparency, a number in [0,1], see argument alpha in
|
begin |
The (corrected) hue in [0,1] at which the color map begins. |
end |
The (corrected) hue in [0,1] at which the color map ends. |
direction |
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. |
option |
A character string indicating the color map option to use. Eight options are available:
|
See viridis
and
viridis.map
for more information on the color
palettes.
Bob Rudis: [email protected]
Simon Garnier: [email protected]
library(scales) show_col(viridis_pal()(12))
library(scales) show_col(viridis_pal()(12))