1 |
# Color scales constructor for ggplot2 |
|
2 |
#' @include color.R |
|
3 |
NULL |
|
4 | ||
5 |
#' Color Scale Builder |
|
6 |
#' |
|
7 |
#' Builds a color scale for \pkg{ggplot2} or \pkg{ggraph}. |
|
8 |
#' @param palette A [`character`] string giving the name of the color scheme to |
|
9 |
#' be used (see [info()]). |
|
10 |
#' @param ... Extra parameters to be passed to the color scale function. |
|
11 |
#' @return A [discrete][ggplot2::discrete_scale] or |
|
12 |
#' [continuous][ggplot2::continuous_scale] scale. |
|
13 |
#' @example inst/examples/ex-pick.R |
|
14 |
#' @author N. Frerebeau |
|
15 |
#' @family ggplot2 scales |
|
16 |
#' @name scale_picker |
|
17 |
#' @rdname scale_picker |
|
18 |
NULL |
|
19 | ||
20 |
#' @export |
|
21 |
#' @rdname scale_picker |
|
22 |
scale_colour_picker <- function(..., palette = "YlOrBr") { |
|
23 | 4x |
fun <- sprintf("scale_colour_%s", palette) |
24 | 4x |
do.call(fun, args = list(...)) |
25 |
} |
|
26 | ||
27 |
#' @export |
|
28 |
#' @rdname scale_picker |
|
29 |
scale_color_picker <- scale_colour_picker |
|
30 | ||
31 |
#' @export |
|
32 |
#' @rdname scale_picker |
|
33 |
scale_fill_picker <- function(..., palette = "YlOrBr") { |
|
34 | 1x |
fun <- sprintf("scale_fill_%s", palette) |
35 | 1x |
do.call(fun, args = list(...)) |
36 |
} |
|
37 | ||
38 |
#' @export |
|
39 |
#' @rdname scale_picker |
|
40 |
scale_edge_colour_picker <- function(..., palette = "YlOrBr") { |
|
41 | 1x |
fun <- sprintf("scale_edge_colour_%s", palette) |
42 | 1x |
do.call(fun, args = list(...)) |
43 |
} |
|
44 | ||
45 |
#' @export |
|
46 |
#' @rdname scale_picker |
|
47 |
scale_edge_color_picker <- scale_edge_colour_picker |
|
48 | ||
49 |
#' @export |
|
50 |
#' @rdname scale_picker |
|
51 |
scale_edge_fill_picker <- function(..., palette = "YlOrBr") { |
|
52 | 1x |
fun <- sprintf("scale_edge_fill_%s", palette) |
53 | 1x |
do.call(fun, args = list(...)) |
54 |
} |
|
55 | ||
56 |
#' Color Scale Constructors |
|
57 |
#' |
|
58 |
#' Builds a discrete or continuous scale for \pkg{ggplot2} according to the |
|
59 |
#' color scheme used. |
|
60 |
#' @param aesthetics The names of the aesthetics that this scale works with. |
|
61 |
#' @param scheme A [`character`] string giving the name of the scheme to be |
|
62 |
#' used (see [color()]). |
|
63 |
#' @param guide A [`function`] used to create a guide or its name. |
|
64 |
#' See [ggplot2::guides()] for more information. |
|
65 |
#' @param reverse A [`logical`] scalar: should the resulting vector of colors |
|
66 |
#' should be reversed? |
|
67 |
#' @param use_names A [`logical`] scalar: should the names of the colors be |
|
68 |
#' preserved? |
|
69 |
#' @param lang A [`character`] string specifying the language for the color |
|
70 |
#' names. It must be one of "`en`" (english, the default) or "`fr`" (french). |
|
71 |
#' @param type A [`character`] string specifying the scale to be |
|
72 |
#' build. It must be one of "`auto`" (the default), "`discrete`" or |
|
73 |
#' "`continuous`". "`discrete`" allows to use a continuous color scheme with |
|
74 |
#' discrete data. "`continuous`" allows to use a discrete color scheme with |
|
75 |
#' continuous data (forces interpolation; see [color()]). |
|
76 |
#' @param midpoint A [`numeric`] value specifying the midpoint (in |
|
77 |
#' data value) of the diverging scale (defaults to \eqn{0}). |
|
78 |
#' @param ... Further arguments passed to [ggplot2::discrete_scale()] |
|
79 |
#' or [ggplot2::continuous_scale()], used respectively for qualitative data |
|
80 |
#' and diverging/sequential data. |
|
81 |
#' @return A [discrete][ggplot2::discrete_scale()] |
|
82 |
#' or [continuous][ggplot2:continuous_scale()] scale. |
|
83 |
#' @author N. Frerebeau |
|
84 |
#' @keywords internal |
|
85 |
#' @noRd |
|
86 |
NULL |
|
87 | ||
88 |
scale_discrete <- function(aesthetics, scheme, guide = "legend", |
|
89 |
reverse = FALSE, use_names = FALSE, |
|
90 |
lang = "en", ...) { |
|
91 |
# Check if ggplot2 is installed |
|
92 | 280x |
assert_package("ggplot2") |
93 | ||
94 |
# Get color scheme |
|
95 | 280x |
palette <- color(scheme, reverse = reverse, names = use_names, lang = lang) |
96 | ||
97 |
# Build scale |
|
98 | 280x |
scale_args <- list(...) |
99 | 280x |
scale_args$guide <- guide |
100 | 280x |
scale_args$na.value <- scale_args$na.value %||% attr(palette, "missing") |
101 | ||
102 | 280x |
do.call( |
103 | 280x |
ggplot2::discrete_scale, |
104 | 280x |
c(aesthetics = aesthetics, palette = palette, scale_args) |
105 |
) |
|
106 |
} |
|
107 | ||
108 |
scale_continuous <- function(aesthetics, scheme, guide = "colourbar", |
|
109 |
reverse = FALSE, range = c(0, 1), midpoint = 0, |
|
110 |
lang = "en", ...) { |
|
111 |
# Validation |
|
112 | 632x |
assert_package("ggplot2") # Check if ggplot2 is installed |
113 | 286x |
if (guide == "edge_colourbar") assert_package("ggraph") |
114 | ||
115 |
# Get color scheme |
|
116 | 632x |
palette <- color(scheme, reverse = reverse, names = FALSE, lang = lang) |
117 | 632x |
max <- attr(palette, "max") |
118 | 632x |
type <- attr(palette, "type") |
119 | ||
120 |
# Build scale |
|
121 | 632x |
scale_args <- list(...) |
122 | 632x |
scale_args$guide <- guide |
123 | 632x |
scale_args$na.value <- scale_args$na.value %||% attr(palette, "missing") |
124 | ||
125 | 632x |
if (type == "diverging") { |
126 | 310x |
scale_args$rescaler <- rescale_mid(mid = midpoint) |
127 |
} |
|
128 | ||
129 | 632x |
palette <- scales::gradient_n_pal(palette(max, range = range)) |
130 | 632x |
do.call( |
131 | 632x |
ggplot2::continuous_scale, |
132 | 632x |
c(aesthetics = aesthetics, palette = palette, scale_args) |
133 |
) |
|
134 |
} |
|
135 | ||
136 |
rescale_mid <- function(mid) { |
|
137 | 310x |
function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) { |
138 | ! |
scale_midpoint(x, to = to, from = from, midpoint = mid) |
139 |
} |
|
140 |
} |
1 |
# Okabe & Ito color scheme |
|
2 |
#' @include color.R |
|
3 |
NULL |
|
4 | ||
5 |
# Discrete ===================================================================== |
|
6 |
#' Okabe and Ito's Discrete Color Scheme for \pkg{ggplot2} and \pkg{ggraph} |
|
7 |
#' |
|
8 |
#' Provides the qualitative color scale from Okabe and Ito 2008. |
|
9 |
#' @param ... Arguments passed to [ggplot2::discrete_scale()]. |
|
10 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
11 |
#' vector of colors be reversed? |
|
12 |
#' @param black_position A [`character`] string giving the position of the black |
|
13 |
#' color. It must be one of "`first`" or "`last`". Any unambiguous substring |
|
14 |
#' can be given. |
|
15 |
#' @param aesthetics A [`character`] string or vector of character |
|
16 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
17 |
#' @details |
|
18 |
#' This qualitative color scheme is used as given (no interpolation): |
|
19 |
#' colors are picked up to the maximum number of supported values (8). |
|
20 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
21 |
#' @references |
|
22 |
#' Okabe, M. & Ito, K. (2008). *Color Universal Design (CUD): How to Make |
|
23 |
#' Figures and Presentations That Are Friendly to Colorblind People*. |
|
24 |
#' URL: \url{https://jfly.uni-koeln.de/color/}. |
|
25 |
#' @example inst/examples/ex-okabeito-discrete.R |
|
26 |
#' @author N. Frerebeau |
|
27 |
#' @family color-blind safe color schemes |
|
28 |
#' @family qualitative color schemes |
|
29 |
#' @family Okabe and Ito's color scheme |
|
30 |
#' @name scale_okabeito_discrete |
|
31 |
#' @rdname scale_okabeito_discrete |
|
32 |
NULL |
|
33 | ||
34 |
#' Get Okabe and Ito's Discrete Color Scheme |
|
35 |
#' |
|
36 |
#' @param black_position A [`character`] string giving the position of the black |
|
37 |
#' color. It must be one of "`first`" or "`last`". Any unambiguous substring |
|
38 |
#' can be given. |
|
39 |
#' @examples |
|
40 |
#' get_okabeito_scale("first") |
|
41 |
#' get_okabeito_scale("last") |
|
42 |
#' @keywords internal |
|
43 |
#' @noRd |
|
44 |
get_okabeito_scale <- function(black_position = c("first", "last")) { |
|
45 | 28x |
black_position <- match.arg(black_position, several.ok = FALSE) |
46 | 6x |
switch (black_position, first = "okabeito", last = "okabeitoblack") |
47 |
} |
|
48 | ||
49 |
#' @export |
|
50 |
#' @rdname scale_okabeito_discrete |
|
51 |
scale_colour_okabeito <- function(..., reverse = FALSE, |
|
52 |
black_position = c("first", "last"), |
|
53 |
aesthetics = "colour") { |
|
54 | 14x |
oi_palette <- get_okabeito_scale(black_position) |
55 | 14x |
scale_discrete(aesthetics, oi_palette, reverse = reverse, ...) |
56 |
} |
|
57 | ||
58 |
#' @export |
|
59 |
#' @rdname scale_okabeito_discrete |
|
60 |
scale_color_okabeito <- scale_colour_okabeito |
|
61 | ||
62 |
#' @export |
|
63 |
#' @rdname scale_okabeito_discrete |
|
64 |
scale_fill_okabeito <- function(..., reverse = FALSE, |
|
65 |
black_position = c("first", "last"), |
|
66 |
aesthetics = "fill") { |
|
67 | 3x |
oi_palette <- get_okabeito_scale(black_position) |
68 | 3x |
scale_discrete(aesthetics, oi_palette, reverse = reverse, ...) |
69 |
} |
|
70 | ||
71 |
#' @export |
|
72 |
#' @rdname scale_okabeito_discrete |
|
73 |
scale_edge_colour_okabeito <- function(..., reverse = FALSE, |
|
74 |
black_position = c("first", "last"), |
|
75 |
aesthetics = "edge_colour") { |
|
76 | 8x |
oi_palette <- get_okabeito_scale(black_position) |
77 | 8x |
scale_discrete(aesthetics, oi_palette, reverse = reverse, ...) |
78 |
} |
|
79 | ||
80 |
#' @export |
|
81 |
#' @rdname scale_okabeito_discrete |
|
82 |
scale_edge_color_okabeito <- scale_edge_colour_okabeito |
|
83 | ||
84 |
#' @export |
|
85 |
#' @rdname scale_okabeito_discrete |
|
86 |
scale_edge_fill_okabeito <- function(..., reverse = FALSE, |
|
87 |
black_position = c("first", "last"), |
|
88 |
aesthetics = "edge_fill") { |
|
89 | 3x |
oi_palette <- get_okabeito_scale(black_position) |
90 | 3x |
scale_discrete(aesthetics, oi_palette, reverse = reverse, ...) |
91 |
} |
1 |
#' Simulate Color-Blindness |
|
2 |
#' |
|
3 |
#' @param x A palette [`function`] that when called with a single |
|
4 |
#' integer argument (the number of levels) returns a vector of colors |
|
5 |
#' (see [color()]). |
|
6 |
#' @param mode A [`character`] string giving the colorblind vision |
|
7 |
#' to be used. It must be one of "`deuteranopia`", "`protanopia`", |
|
8 |
#' "`tritanopia`" or "`achromatopsia`". Any unambiguous substring can be given. |
|
9 |
#' @return |
|
10 |
#' A palette [`function`] that returns a vector of anomalized |
|
11 |
#' colors. All the attributes of the initial palette function are inherited, |
|
12 |
#' with a supplementary attribute "`mode`" giving the corresponding |
|
13 |
#' color-blind vision. |
|
14 |
#' @example inst/examples/ex-change.R |
|
15 |
#' @references |
|
16 |
#' Brettel, H., Viénot, F. and Mollon, J. D. (1997). Computerized Simulation of |
|
17 |
#' Color Appearance for Dichromats. *Journal of the Optical Society of America |
|
18 |
#' A*, 14(10), p. 2647-2655. \doi{10.1364/JOSAA.14.002647}. |
|
19 |
#' |
|
20 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
21 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
22 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
23 |
#' |
|
24 |
#' Viénot, F., Brettel, H. and Mollon, J. D. (1999). Digital Video |
|
25 |
#' Colourmaps for Checking the Legibility of Displays by Dichromats. |
|
26 |
#' *Color Research & Application*, 24(4), p. 243-52. |
|
27 |
#' \doi{10.1002/(SICI)1520-6378(199908)24:4<243::AID-COL5>3.0.CO;2-3}. |
|
28 |
#' @author N. Frerebeau |
|
29 |
#' @family diagnostic tools |
|
30 |
#' @export |
|
31 |
change <- function(x, mode) { |
|
32 | 4x |
fun <- function(n) { anomalize(x(n), mode = mode) } |
33 | 4x |
attributes(fun) <- attributes(x) |
34 | 4x |
attr(fun, "mode") <- mode |
35 | 4x |
fun |
36 |
} |
|
37 | ||
38 |
#' Anomalize |
|
39 |
#' |
|
40 |
#' @param x A [`character`] vector of color codes. |
|
41 |
#' @param mode A [`character`] string giving the colorblind vision |
|
42 |
#' to be used. It must be one of "`deuteranopia`", "`protanopia`", |
|
43 |
#' "`tritanopia`" or "`achromatopsia`". Any unambiguous substring can be given. |
|
44 |
#' @return A [`character`] vector of color codes. |
|
45 |
#' @author N. Frerebeau |
|
46 |
#' @keywords internal |
|
47 |
#' @noRd |
|
48 |
anomalize <- function(x, mode = c("deuteranopia", "protanopia", "tritanopia", |
|
49 |
"achromatopsia")) { |
|
50 |
# Validation |
|
51 | 8x |
mode <- match.arg(mode, several.ok = FALSE) |
52 | ||
53 |
# Convert to RGB color code |
|
54 | 8x |
RGB1 <- t(grDevices::col2rgb(x, alpha = FALSE)) |
55 | ||
56 |
# Dichromat |
|
57 | 8x |
S <- switch ( |
58 | 8x |
mode, |
59 |
# Green-blindness |
|
60 | 8x |
deuteranopia = rbind( |
61 |
# Red, Green, Blue |
|
62 | 8x |
c(1, 0, 0), |
63 | 8x |
c(0.9513092, 0, 0.04866992), |
64 | 8x |
c(0, 0, 1) |
65 |
), |
|
66 |
# Red-blindness |
|
67 | 8x |
protanopia = rbind( |
68 |
# Red, Green, Blue |
|
69 | 8x |
c(0, 1.05118294, -0.05116099), |
70 | 8x |
c(0, 1, 0), |
71 | 8x |
c(0, 0, 1) |
72 |
), |
|
73 |
# Blue-blindness |
|
74 | 8x |
tritanopia = rbind( |
75 |
# Red, Green, Blue |
|
76 | 8x |
c(1, 0, 0), |
77 | 8x |
c(0, 1, 0), |
78 | 8x |
c(-0.86744736, 1.86727089, 0) |
79 |
), |
|
80 |
# Achromatopsia |
|
81 | 8x |
achromatopsia = rbind( |
82 |
# Red, Green, Blue |
|
83 | 8x |
c(0, 0, 1), |
84 | 8x |
c(0, 0, 1), |
85 | 8x |
c(0, 0, 1) |
86 |
) |
|
87 |
) |
|
88 | ||
89 |
# Convert colors from the RGB color space to the LMS color space |
|
90 |
# RGB_to_LMS <- .XYZ_to_LMS %*% .sRGB_to_XYZ |
|
91 |
# RGB2 <- solve(RGB_to_LMS) %*% S %*% RGB_to_LMS %*% RGB1 |
|
92 | ||
93 |
# Conversion |
|
94 | 8x |
LMS <- RGB2LMS(RGB1) %*% t(S) |
95 | 8x |
RGB2 <- LMS2RGB(LMS) |
96 | ||
97 |
# RGB constraints |
|
98 | 8x |
for (i in 1:nrow(RGB2)) { |
99 | 56x |
RGB2[i, ] <- pmin(RGB2[i, ], rep(255, 3)) |
100 | 56x |
RGB2[i, ] <- pmax(RGB2[i, ], rep(0, 3)) |
101 |
} |
|
102 | ||
103 |
# Convert to Hex color code |
|
104 | 8x |
grDevices::rgb(RGB2, names = names(x), maxColorValue = 255) |
105 |
} |
|
106 | ||
107 |
# Color Conversion |
|
108 | ||
109 |
#' CMYK to/from RGB Color Conversion |
|
110 |
#' |
|
111 |
#' @param cyan,magenta,yellow,black,red,blue,green A [`numeric`] vector with |
|
112 |
#' values in \eqn{[0, max]}. |
|
113 |
#' @param max A [`numeric`] value giving the maximum of the color values range. |
|
114 |
#' @return An integer matrix with three or four columns. |
|
115 |
#' @author N. Frerebeau |
|
116 |
#' @keywords internal |
|
117 |
#' @noRd |
|
118 |
NULL |
|
119 | ||
120 |
CMYK2RGB <- function(cyan, magenta, yellow, black, max = 1) { |
|
121 | 4x |
if (missing(magenta) && missing(yellow) && missing(black)) { |
122 | 1x |
if (is.matrix(cyan) || is.data.frame(cyan)) { |
123 | ! |
if (ncol(cyan) < 4L) stop("At least 4 columns needed.", call. = FALSE) |
124 | 1x |
cyan <- data.matrix(cyan) |
125 | 1x |
CMY <- cyan[, -4] |
126 | 1x |
black <- cyan[, 4] |
127 |
} |
|
128 |
} else { |
|
129 | 3x |
CMY <- cbind(cyan, magenta, yellow) |
130 |
} |
|
131 | 4x |
CMY <- CMY / max |
132 | 4x |
K <- black / max |
133 | ||
134 | 4x |
RGB <- 255 * (1 - CMY) * (1 - K) |
135 | 4x |
colnames(RGB) <- c("R", "G", "B") |
136 | 4x |
return(RGB) |
137 |
} |
|
138 | ||
139 |
RGB2CMYB <- function(red, green, blue, max = 255) { |
|
140 | 4x |
if (missing(green) && missing(blue)) { |
141 | 1x |
if (is.matrix(red) || is.data.frame(red)) { |
142 | ! |
if (ncol(red) < 3L) stop("At least 3 columns needed.", call. = FALSE) |
143 | 1x |
RGB <- data.matrix(red) |
144 |
} |
|
145 |
} else { |
|
146 | 3x |
RGB <- cbind(red, green, blue) |
147 |
} |
|
148 | 4x |
RGB <- RGB / max |
149 | 4x |
K <- 1 - apply(X = RGB, MARGIN = 1, FUN = max) |
150 | 4x |
CMY <- (1 - RGB - K) / (1 - K) |
151 | 4x |
CMYK <- cbind(CMY, K) |
152 | 4x |
CMYK[is.na(CMYK)] <- 0 # Fix zero division |
153 | 4x |
colnames(CMYK) <- c("C", "M", "Y", "K") |
154 | 4x |
return(CMYK) |
155 |
} |
|
156 | ||
157 |
#' RGB to/from XYZ Color Conversion |
|
158 |
#' |
|
159 |
#' @param red,blue,green A [`numeric`] vector with values in \eqn{[0, max]}. |
|
160 |
#' @param x,y,z A [`numeric`] vector of color coordinates. |
|
161 |
#' @param max A [`numeric`] value giving the maximum of the color values range. |
|
162 |
#' @return A numeric matrix with three columns. |
|
163 |
#' @author N. Frerebeau |
|
164 |
#' @keywords internal |
|
165 |
#' @noRd |
|
166 |
NULL |
|
167 | ||
168 |
gamma_expand <- function(RGB) { |
|
169 | 13x |
u <- RGB > 0.04045 |
170 | 13x |
sRGB <- RGB / 12.92 |
171 | 13x |
sRGB[u] <- ((200 * RGB[u] + 11) / 211)^(12 / 5) |
172 | 13x |
return(sRGB) |
173 |
} |
|
174 |
gamma_compress <- function(sRGB) { |
|
175 | 12x |
u <- sRGB > 0.0031308 |
176 | 12x |
RGB <- sRGB * 12.92 |
177 | 12x |
RGB[u] <- (211 * sRGB[u]^(5 / 12) - 11) / 200 |
178 | 12x |
return(RGB) |
179 |
} |
|
180 | ||
181 |
XYZ2RGB <- function(x, y, z, max_rgb = 255) { |
|
182 | 4x |
if (missing(y) && missing(z)) { |
183 | 1x |
if (is.matrix(x) || is.data.frame(x)) { |
184 | ! |
if (ncol(x) < 3L) stop("At least 3 columns needed.", call. = FALSE) |
185 | 1x |
XYZ <- data.matrix(x) |
186 |
} |
|
187 |
} else { |
|
188 | 3x |
XYZ <- cbind(x, y, z) |
189 |
} |
|
190 | 4x |
sRGB <- XYZ %*% t(.XYZ_to_sRGB) |
191 | 4x |
colnames(sRGB) <- c("R", "G", "B") |
192 | ||
193 |
# gamma-compressed values |
|
194 | 4x |
RGB <- gamma_compress(sRGB) |
195 | ||
196 | 4x |
return(RGB * max_rgb) |
197 |
} |
|
198 | ||
199 |
RGB2XYZ <- function(red, green, blue, max_rgb = 255) { |
|
200 | 5x |
if (missing(green) && missing(blue)) { |
201 | 2x |
if (is.matrix(red) || is.data.frame(red)) { |
202 | ! |
if (ncol(red) < 3L) stop("At least 3 columns needed.", call. = FALSE) |
203 | 2x |
RGB <- data.matrix(red) |
204 |
} |
|
205 |
} else { |
|
206 | 3x |
RGB <- cbind(red, green, blue) |
207 |
} |
|
208 | 5x |
RGB <- RGB / max_rgb |
209 | ||
210 |
# gamma-expanded values |
|
211 | 5x |
sRGB <- gamma_expand(RGB) |
212 | ||
213 | 5x |
XYZ <- sRGB %*% t(.sRGB_to_XYZ) |
214 | 5x |
colnames(XYZ) <- c("X", "Y", "Z") |
215 | 5x |
return(XYZ) |
216 |
} |
|
217 | ||
218 |
#' RGB to/from LMS Lab Color Conversion |
|
219 |
#' |
|
220 |
#' @param red,blue,green A [`numeric`] vector with values in \eqn{[0, max]}. |
|
221 |
#' @param max A [`numeric`] value giving the maximum of the color values range. |
|
222 |
#' @return A numeric matrix with three rows. |
|
223 |
#' @author N. Frerebeau |
|
224 |
#' @keywords internal |
|
225 |
#' @noRd |
|
226 |
NULL |
|
227 | ||
228 |
RGB2LMS <- function(red, green, blue, max = 255) { |
|
229 | 8x |
if (missing(green) && missing(blue)) { |
230 | 8x |
if (is.matrix(red) || is.data.frame(red)) { |
231 | ! |
if (ncol(red) < 3L) stop("At least 3 columns needed.", call. = FALSE) |
232 | 8x |
RGB <- data.matrix(red) |
233 |
} |
|
234 |
} else { |
|
235 | ! |
RGB <- cbind(red, green, blue) |
236 |
} |
|
237 | 8x |
RGB <- RGB / max |
238 | ||
239 |
# gamma-expanded values |
|
240 | 8x |
sRGB <- gamma_expand(RGB) |
241 | ||
242 | 8x |
LMS <- sRGB %*% t(.XYZ_to_LMS %*% .sRGB_to_XYZ) |
243 | 8x |
colnames(LMS) <- c("L", "M", "S") |
244 | 8x |
return(LMS) |
245 |
} |
|
246 | ||
247 |
LMS2RGB <- function(long, medium, short, max = 255) { |
|
248 | 8x |
if (missing(medium) && missing(short)) { |
249 | 8x |
if (is.matrix(long) || is.data.frame(long)) { |
250 | ! |
if (ncol(long) < 3L) stop("At least 3 columns needed.", call. = FALSE) |
251 | 8x |
LMS <- data.matrix(long) |
252 |
} |
|
253 |
} else { |
|
254 | ! |
LMS <- cbind(long, medium, short) |
255 |
} |
|
256 | ||
257 | 8x |
sRGB <- LMS %*% t(solve(.XYZ_to_LMS %*% .sRGB_to_XYZ)) |
258 | 8x |
colnames(sRGB) <- c("R", "G", "B") |
259 | ||
260 |
# gamma-compressed values |
|
261 | 8x |
RGB <- gamma_compress(sRGB) |
262 | ||
263 | 8x |
return(RGB * max) |
264 |
} |
|
265 | ||
266 |
#' XYZ to CIE Lab Color Conversion |
|
267 |
#' |
|
268 |
#' @param x,y,z A [`numeric`] vector of color coordinates. |
|
269 |
#' @param white A length-three [`numeric`] vector giving a reference white |
|
270 |
#' coordinates (default to D65). |
|
271 |
#' @return A numeric matrix with three columns. |
|
272 |
#' @author N. Frerebeau |
|
273 |
#' @keywords internal |
|
274 |
#' @noRd |
|
275 |
NULL |
|
276 | ||
277 |
XYZ2Lab <- function(x, y, z, white = c(x = 0.95047, y = 1.00000, z = 1.08883)) { |
|
278 | 1x |
if (missing(y) && missing(z)) { |
279 | 1x |
if (is.matrix(x) || is.data.frame(x)) { |
280 | ! |
if (ncol(x) < 3L) stop("At least 3 columns needed.", call. = FALSE) |
281 | 1x |
XYZ <- data.matrix(x) |
282 | 1x |
x <- XYZ[, 1] |
283 | 1x |
y <- XYZ[, 2] |
284 | 1x |
z <- XYZ[, 3] |
285 |
} |
|
286 |
} |
|
287 | ||
288 |
# Actual CIE standards |
|
289 | 1x |
f <- function(a, e = 0.008856, k = 903.3) { |
290 | 5x |
a_e <- a <= e |
291 | 5x |
b <- a^(1/3) |
292 | 5x |
b[a_e] <- (k * a[a_e] + 16) / 116 |
293 | 5x |
b |
294 |
} |
|
295 | ||
296 | 1x |
x <- x / white[[1L]] |
297 | 1x |
y <- y / white[[2L]] |
298 | 1x |
z <- z / white[[3L]] |
299 | ||
300 | 1x |
Lab <- cbind( |
301 | 1x |
L = 116 * f(y) - 16, |
302 | 1x |
a = 500 * (f(x) - f(y)), |
303 | 1x |
b = 200 * (f(y) - f(z)) |
304 |
) |
|
305 | 1x |
return(Lab) |
306 |
} |
1 |
# Fabio Crameri's color schemes |
|
2 |
#' @include color.R |
|
3 |
NULL |
|
4 | ||
5 |
# Diverging ==================================================================== |
|
6 |
## broc ------------------------------------------------------------------------ |
|
7 |
#' Fabio Crameri's *broc* Diverging Color Scheme |
|
8 |
#' |
|
9 |
#' @param ... Arguments passed to [ggplot2::continuous_scale()]. |
|
10 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
11 |
#' vector of colors be reversed? |
|
12 |
#' @param range A length-two [`numeric`] vector specifying the |
|
13 |
#' fraction of the scheme's color domain to keep. |
|
14 |
#' @param midpoint A length-one [`numeric`] vector giving the midpoint |
|
15 |
#' (in data value) of the diverging scale. Defaults to `0`. |
|
16 |
#' @param aesthetics A [`character`] string or vector of character |
|
17 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
18 |
#' @param discrete A [`logical`] scalar: should the color scheme be |
|
19 |
#' used as a discrete scale? |
|
20 |
#' @inheritSection crameri Diverging Color Schemes |
|
21 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
22 |
#' @references |
|
23 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
24 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
25 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
26 |
#' |
|
27 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
28 |
#' science communication. *Nature Communications*, 11, 5444. |
|
29 |
#' \doi{10.1038/s41467-020-19160-7} |
|
30 |
#' @source |
|
31 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
32 |
#' \doi{10.5281/zenodo.4491293} |
|
33 |
#' @example inst/examples/ex-crameri-diverging.R |
|
34 |
#' @author N. Frerebeau |
|
35 |
#' @family diverging color schemes |
|
36 |
#' @family Fabio Crameri's color schemes |
|
37 |
#' @name scale_crameri_broc |
|
38 |
#' @rdname scale_crameri_broc |
|
39 |
NULL |
|
40 | ||
41 |
#' @export |
|
42 |
#' @rdname scale_crameri_broc |
|
43 |
scale_colour_broc <- function(..., reverse = FALSE, range = c(0, 1), |
|
44 |
midpoint = 0, discrete = FALSE, |
|
45 |
aesthetics = "colour") { |
|
46 | 6x |
if (discrete) { |
47 | ! |
scale_discrete(aesthetics, "broc", reverse = reverse, ...) |
48 |
} else { |
|
49 | 6x |
scale_continuous(aesthetics, "broc", reverse = reverse, range = range, |
50 | 6x |
midpoint = midpoint, ...) |
51 |
} |
|
52 |
} |
|
53 | ||
54 |
#' @export |
|
55 |
#' @rdname scale_crameri_broc |
|
56 |
scale_color_broc <- scale_colour_broc |
|
57 | ||
58 |
#' @export |
|
59 |
#' @rdname scale_crameri_broc |
|
60 |
scale_fill_broc <- function(..., reverse = FALSE, range = c(0, 1), |
|
61 |
midpoint = 0, discrete = FALSE, |
|
62 |
aesthetics = "fill") { |
|
63 | 4x |
if (discrete) { |
64 | ! |
scale_discrete(aesthetics, "broc", reverse = reverse, ...) |
65 |
} else { |
|
66 | 4x |
scale_continuous(aesthetics, "broc", reverse = reverse, range = range, |
67 | 4x |
midpoint = midpoint, ...) |
68 |
} |
|
69 |
} |
|
70 | ||
71 |
#' @export |
|
72 |
#' @rdname scale_crameri_broc |
|
73 |
scale_edge_colour_broc <- function(..., reverse = FALSE, range = c(0, 1), |
|
74 |
midpoint = 0, discrete = FALSE, |
|
75 |
aesthetics = "edge_colour") { |
|
76 | 6x |
if (discrete) { |
77 | ! |
scale_discrete(aesthetics, "broc", reverse = reverse, ...) |
78 |
} else { |
|
79 | 6x |
scale_continuous(aesthetics, "broc", guide = "edge_colourbar", |
80 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
81 |
} |
|
82 |
} |
|
83 | ||
84 |
#' @export |
|
85 |
#' @rdname scale_crameri_broc |
|
86 |
scale_edge_color_broc <- scale_edge_colour_broc |
|
87 | ||
88 |
#' @export |
|
89 |
#' @rdname scale_crameri_broc |
|
90 |
scale_edge_fill_broc <- function(..., reverse = FALSE, range = c(0, 1), |
|
91 |
midpoint = 0, discrete = FALSE, |
|
92 |
aesthetics = "edge_fill") { |
|
93 | 4x |
if (discrete) { |
94 | ! |
scale_discrete(aesthetics, "broc", reverse = reverse, ...) |
95 |
} else { |
|
96 | 4x |
scale_continuous(aesthetics, "broc", guide = "edge_colourbar", |
97 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
98 |
} |
|
99 |
} |
|
100 | ||
101 |
## cork ------------------------------------------------------------------------ |
|
102 |
#' Fabio Crameri's *cork* Diverging Color Scheme |
|
103 |
#' |
|
104 |
#' @inheritParams scale_crameri_broc |
|
105 |
#' @inheritSection crameri Diverging Color Schemes |
|
106 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
107 |
#' @references |
|
108 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
109 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
110 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
111 |
#' |
|
112 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
113 |
#' science communication. *Nature Communications*, 11, 5444. |
|
114 |
#' \doi{10.1038/s41467-020-19160-7} |
|
115 |
#' @source |
|
116 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
117 |
#' \doi{10.5281/zenodo.4491293} |
|
118 |
#' @example inst/examples/ex-crameri-diverging.R |
|
119 |
#' @author N. Frerebeau |
|
120 |
#' @family diverging color schemes |
|
121 |
#' @family Fabio Crameri's color schemes |
|
122 |
#' @name scale_crameri_cork |
|
123 |
#' @rdname scale_crameri_cork |
|
124 |
NULL |
|
125 | ||
126 |
#' @export |
|
127 |
#' @rdname scale_crameri_cork |
|
128 |
scale_colour_cork <- function(..., reverse = FALSE, range = c(0, 1), |
|
129 |
midpoint = 0, discrete = FALSE, |
|
130 |
aesthetics = "colour") { |
|
131 | 6x |
if (discrete) { |
132 | ! |
scale_discrete(aesthetics, "cork", reverse = reverse, ...) |
133 |
} else { |
|
134 | 6x |
scale_continuous(aesthetics, "cork", reverse = reverse, range = range, |
135 | 6x |
midpoint = midpoint, ...) |
136 |
} |
|
137 |
} |
|
138 | ||
139 |
#' @export |
|
140 |
#' @rdname scale_crameri_cork |
|
141 |
scale_color_cork <- scale_colour_cork |
|
142 | ||
143 |
#' @export |
|
144 |
#' @rdname scale_crameri_cork |
|
145 |
scale_fill_cork <- function(..., reverse = FALSE, range = c(0, 1), |
|
146 |
midpoint = 0, discrete = FALSE, |
|
147 |
aesthetics = "fill") { |
|
148 | 4x |
if (discrete) { |
149 | ! |
scale_discrete(aesthetics, "cork", reverse = reverse, ...) |
150 |
} else { |
|
151 | 4x |
scale_continuous(aesthetics, "cork", reverse = reverse, range = range, |
152 | 4x |
midpoint = midpoint, ...) |
153 |
} |
|
154 |
} |
|
155 | ||
156 |
#' @export |
|
157 |
#' @rdname scale_crameri_cork |
|
158 |
scale_edge_colour_cork <- function(..., reverse = FALSE, range = c(0, 1), |
|
159 |
midpoint = 0, discrete = FALSE, |
|
160 |
aesthetics = "edge_colour") { |
|
161 | 6x |
if (discrete) { |
162 | ! |
scale_discrete(aesthetics, "cork", reverse = reverse, ...) |
163 |
} else { |
|
164 | 6x |
scale_continuous(aesthetics, "cork", guide = "edge_colourbar", |
165 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
166 |
} |
|
167 |
} |
|
168 | ||
169 |
#' @export |
|
170 |
#' @rdname scale_crameri_cork |
|
171 |
scale_edge_color_cork <- scale_edge_colour_cork |
|
172 | ||
173 |
#' @export |
|
174 |
#' @rdname scale_crameri_cork |
|
175 |
scale_edge_fill_cork <- function(..., reverse = FALSE, range = c(0, 1), |
|
176 |
midpoint = 0, discrete = FALSE, |
|
177 |
aesthetics = "edge_fill") { |
|
178 | 4x |
if (discrete) { |
179 | ! |
scale_discrete(aesthetics, "cork", reverse = reverse, ...) |
180 |
} else { |
|
181 | 4x |
scale_continuous(aesthetics, "cork", guide = "edge_colourbar", |
182 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
183 |
} |
|
184 |
} |
|
185 | ||
186 |
## vik ------------------------------------------------------------------------- |
|
187 |
#' Fabio Crameri's *vik* Diverging Color Scheme |
|
188 |
#' |
|
189 |
#' @inheritParams scale_crameri_broc |
|
190 |
#' @inheritSection crameri Diverging Color Schemes |
|
191 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
192 |
#' @references |
|
193 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
194 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
195 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
196 |
#' |
|
197 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
198 |
#' science communication. *Nature Communications*, 11, 5444. |
|
199 |
#' \doi{10.1038/s41467-020-19160-7} |
|
200 |
#' @source |
|
201 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
202 |
#' \doi{10.5281/zenodo.4491293} |
|
203 |
#' @example inst/examples/ex-crameri-diverging.R |
|
204 |
#' @author N. Frerebeau |
|
205 |
#' @family diverging color schemes |
|
206 |
#' @family Fabio Crameri's color schemes |
|
207 |
#' @name scale_crameri_vik |
|
208 |
#' @rdname scale_crameri_vik |
|
209 |
NULL |
|
210 | ||
211 |
#' @export |
|
212 |
#' @rdname scale_crameri_vik |
|
213 |
scale_colour_vik <- function(..., reverse = FALSE, range = c(0, 1), |
|
214 |
midpoint = 0, discrete = FALSE, |
|
215 |
aesthetics = "colour") { |
|
216 | 6x |
if (discrete) { |
217 | ! |
scale_discrete(aesthetics, "vik", reverse = reverse, ...) |
218 |
} else { |
|
219 | 6x |
scale_continuous(aesthetics, "vik", reverse = reverse, range = range, |
220 | 6x |
midpoint = midpoint, ...) |
221 |
} |
|
222 |
} |
|
223 | ||
224 |
#' @export |
|
225 |
#' @rdname scale_crameri_vik |
|
226 |
scale_color_vik <- scale_colour_vik |
|
227 | ||
228 |
#' @export |
|
229 |
#' @rdname scale_crameri_vik |
|
230 |
scale_fill_vik <- function(..., reverse = FALSE, range = c(0, 1), |
|
231 |
midpoint = 0, discrete = FALSE, |
|
232 |
aesthetics = "fill") { |
|
233 | 4x |
if (discrete) { |
234 | ! |
scale_discrete(aesthetics, "vik", reverse = reverse, ...) |
235 |
} else { |
|
236 | 4x |
scale_continuous(aesthetics, "vik", reverse = reverse, range = range, |
237 | 4x |
midpoint = midpoint, ...) |
238 |
} |
|
239 |
} |
|
240 | ||
241 |
#' @export |
|
242 |
#' @rdname scale_crameri_vik |
|
243 |
scale_edge_colour_vik <- function(..., reverse = FALSE, range = c(0, 1), |
|
244 |
midpoint = 0, discrete = FALSE, |
|
245 |
aesthetics = "edge_colour") { |
|
246 | 6x |
if (discrete) { |
247 | ! |
scale_discrete(aesthetics, "vik", reverse = reverse, ...) |
248 |
} else { |
|
249 | 6x |
scale_continuous(aesthetics, "vik", guide = "edge_colourbar", |
250 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
251 |
} |
|
252 |
} |
|
253 | ||
254 |
#' @export |
|
255 |
#' @rdname scale_crameri_vik |
|
256 |
scale_edge_color_vik <- scale_edge_colour_vik |
|
257 | ||
258 |
#' @export |
|
259 |
#' @rdname scale_crameri_vik |
|
260 |
scale_edge_fill_vik <- function(..., reverse = FALSE, range = c(0, 1), |
|
261 |
midpoint = 0, discrete = FALSE, |
|
262 |
aesthetics = "edge_fill") { |
|
263 | 4x |
if (discrete) { |
264 | ! |
scale_discrete(aesthetics, "vik", reverse = reverse, ...) |
265 |
} else { |
|
266 | 4x |
scale_continuous(aesthetics, "vik", guide = "edge_colourbar", |
267 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
268 |
} |
|
269 |
} |
|
270 | ||
271 |
## lisbon ---------------------------------------------------------------------- |
|
272 |
#' Fabio Crameri's *lisbon* Diverging Color Scheme |
|
273 |
#' |
|
274 |
#' @inheritParams scale_crameri_broc |
|
275 |
#' @inheritSection crameri Diverging Color Schemes |
|
276 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
277 |
#' @references |
|
278 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
279 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
280 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
281 |
#' |
|
282 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
283 |
#' science communication. *Nature Communications*, 11, 5444. |
|
284 |
#' \doi{10.1038/s41467-020-19160-7} |
|
285 |
#' @source |
|
286 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
287 |
#' \doi{10.5281/zenodo.4491293} |
|
288 |
#' @example inst/examples/ex-crameri-diverging.R |
|
289 |
#' @author N. Frerebeau |
|
290 |
#' @family diverging color schemes |
|
291 |
#' @family Fabio Crameri's color schemes |
|
292 |
#' @name scale_crameri_lisbon |
|
293 |
#' @rdname scale_crameri_lisbon |
|
294 |
NULL |
|
295 | ||
296 |
#' @export |
|
297 |
#' @rdname scale_crameri_lisbon |
|
298 |
scale_colour_lisbon <- function(..., reverse = FALSE, range = c(0, 1), |
|
299 |
midpoint = 0, discrete = FALSE, |
|
300 |
aesthetics = "colour") { |
|
301 | 6x |
if (discrete) { |
302 | ! |
scale_discrete(aesthetics, "lisbon", reverse = reverse, ...) |
303 |
} else { |
|
304 | 6x |
scale_continuous(aesthetics, "lisbon", reverse = reverse, range = range, |
305 | 6x |
midpoint = midpoint, ...) |
306 |
} |
|
307 |
} |
|
308 | ||
309 |
#' @export |
|
310 |
#' @rdname scale_crameri_lisbon |
|
311 |
scale_color_lisbon <- scale_colour_lisbon |
|
312 | ||
313 |
#' @export |
|
314 |
#' @rdname scale_crameri_lisbon |
|
315 |
scale_fill_lisbon <- function(..., reverse = FALSE, range = c(0, 1), |
|
316 |
midpoint = 0, discrete = FALSE, |
|
317 |
aesthetics = "fill") { |
|
318 | 4x |
if (discrete) { |
319 | ! |
scale_discrete(aesthetics, "lisbon", reverse = reverse, ...) |
320 |
} else { |
|
321 | 4x |
scale_continuous(aesthetics, "lisbon", reverse = reverse, range = range, |
322 | 4x |
midpoint = midpoint, ...) |
323 |
} |
|
324 |
} |
|
325 | ||
326 |
#' @export |
|
327 |
#' @rdname scale_crameri_lisbon |
|
328 |
scale_edge_colour_lisbon <- function(..., reverse = FALSE, range = c(0, 1), |
|
329 |
midpoint = 0, discrete = FALSE, |
|
330 |
aesthetics = "edge_colour") { |
|
331 | 6x |
if (discrete) { |
332 | ! |
scale_discrete(aesthetics, "lisbon", reverse = reverse, ...) |
333 |
} else { |
|
334 | 6x |
scale_continuous(aesthetics, "lisbon", guide = "edge_colourbar", |
335 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
336 |
} |
|
337 |
} |
|
338 | ||
339 |
#' @export |
|
340 |
#' @rdname scale_crameri_lisbon |
|
341 |
scale_edge_color_lisbon <- scale_edge_colour_lisbon |
|
342 | ||
343 |
#' @export |
|
344 |
#' @rdname scale_crameri_lisbon |
|
345 |
scale_edge_fill_lisbon <- function(..., reverse = FALSE, range = c(0, 1), |
|
346 |
midpoint = 0, discrete = FALSE, |
|
347 |
aesthetics = "edge_fill") { |
|
348 | 4x |
if (discrete) { |
349 | ! |
scale_discrete(aesthetics, "lisbon", reverse = reverse, ...) |
350 |
} else { |
|
351 | 4x |
scale_continuous(aesthetics, "lisbon", guide = "edge_colourbar", |
352 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
353 |
} |
|
354 |
} |
|
355 | ||
356 |
## tofino ---------------------------------------------------------------------- |
|
357 |
#' Fabio Crameri's *tofino* Diverging Color Scheme |
|
358 |
#' |
|
359 |
#' @inheritParams scale_crameri_broc |
|
360 |
#' @inheritSection crameri Diverging Color Schemes |
|
361 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
362 |
#' @references |
|
363 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
364 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
365 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
366 |
#' |
|
367 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
368 |
#' science communication. *Nature Communications*, 11, 5444. |
|
369 |
#' \doi{10.1038/s41467-020-19160-7} |
|
370 |
#' @source |
|
371 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
372 |
#' \doi{10.5281/zenodo.4491293} |
|
373 |
#' @example inst/examples/ex-crameri-diverging.R |
|
374 |
#' @author N. Frerebeau |
|
375 |
#' @family diverging color schemes |
|
376 |
#' @family Fabio Crameri's color schemes |
|
377 |
#' @name scale_crameri_tofino |
|
378 |
#' @rdname scale_crameri_tofino |
|
379 |
NULL |
|
380 | ||
381 |
#' @export |
|
382 |
#' @rdname scale_crameri_tofino |
|
383 |
scale_colour_tofino <- function(..., reverse = FALSE, range = c(0, 1), |
|
384 |
midpoint = 0, discrete = FALSE, |
|
385 |
aesthetics = "colour") { |
|
386 | 6x |
if (discrete) { |
387 | ! |
scale_discrete(aesthetics, "tofino", reverse = reverse, ...) |
388 |
} else { |
|
389 | 6x |
scale_continuous(aesthetics, "tofino", reverse = reverse, range = range, |
390 | 6x |
midpoint = midpoint, ...) |
391 |
} |
|
392 |
} |
|
393 | ||
394 |
#' @export |
|
395 |
#' @rdname scale_crameri_tofino |
|
396 |
scale_color_tofino <- scale_colour_tofino |
|
397 | ||
398 |
#' @export |
|
399 |
#' @rdname scale_crameri_tofino |
|
400 |
scale_fill_tofino <- function(..., reverse = FALSE, range = c(0, 1), |
|
401 |
midpoint = 0, discrete = FALSE, |
|
402 |
aesthetics = "fill") { |
|
403 | 4x |
if (discrete) { |
404 | ! |
scale_discrete(aesthetics, "tofino", reverse = reverse, ...) |
405 |
} else { |
|
406 | 4x |
scale_continuous(aesthetics, "tofino", reverse = reverse, range = range, |
407 | 4x |
midpoint = midpoint, ...) |
408 |
} |
|
409 |
} |
|
410 | ||
411 |
#' @export |
|
412 |
#' @rdname scale_crameri_tofino |
|
413 |
scale_edge_colour_tofino <- function(..., reverse = FALSE, range = c(0, 1), |
|
414 |
midpoint = 0, discrete = FALSE, |
|
415 |
aesthetics = "edge_colour") { |
|
416 | 6x |
if (discrete) { |
417 | ! |
scale_discrete(aesthetics, "tofino", reverse = reverse, ...) |
418 |
} else { |
|
419 | 6x |
scale_continuous(aesthetics, "tofino", guide = "edge_colourbar", |
420 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
421 |
} |
|
422 |
} |
|
423 | ||
424 |
#' @export |
|
425 |
#' @rdname scale_crameri_tofino |
|
426 |
scale_edge_color_tofino <- scale_edge_colour_tofino |
|
427 | ||
428 |
#' @export |
|
429 |
#' @rdname scale_crameri_tofino |
|
430 |
scale_edge_fill_tofino <- function(..., reverse = FALSE, range = c(0, 1), |
|
431 |
midpoint = 0, discrete = FALSE, |
|
432 |
aesthetics = "edge_fill") { |
|
433 | 4x |
if (discrete) { |
434 | ! |
scale_discrete(aesthetics, "tofino", reverse = reverse, ...) |
435 |
} else { |
|
436 | 4x |
scale_continuous(aesthetics, "tofino", guide = "edge_colourbar", |
437 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
438 |
} |
|
439 |
} |
|
440 | ||
441 |
## berlin ---------------------------------------------------------------------- |
|
442 |
#' Fabio Crameri's *berlin* Diverging Color Scheme |
|
443 |
#' |
|
444 |
#' @inheritParams scale_crameri_broc |
|
445 |
#' @inheritSection crameri Diverging Color Schemes |
|
446 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
447 |
#' @references |
|
448 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
449 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
450 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
451 |
#' |
|
452 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
453 |
#' science communication. *Nature Communications*, 11, 5444. |
|
454 |
#' \doi{10.1038/s41467-020-19160-7} |
|
455 |
#' @source |
|
456 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
457 |
#' \doi{10.5281/zenodo.4491293} |
|
458 |
#' @example inst/examples/ex-crameri-diverging.R |
|
459 |
#' @author N. Frerebeau |
|
460 |
#' @family diverging color schemes |
|
461 |
#' @family Fabio Crameri's color schemes |
|
462 |
#' @name scale_crameri_berlin |
|
463 |
#' @rdname scale_crameri_berlin |
|
464 |
NULL |
|
465 | ||
466 |
#' @export |
|
467 |
#' @rdname scale_crameri_berlin |
|
468 |
scale_colour_berlin <- function(..., reverse = FALSE, range = c(0, 1), |
|
469 |
midpoint = 0, discrete = FALSE, |
|
470 |
aesthetics = "colour") { |
|
471 | 6x |
if (discrete) { |
472 | ! |
scale_discrete(aesthetics, "berlin", reverse = reverse, ...) |
473 |
} else { |
|
474 | 6x |
scale_continuous(aesthetics, "berlin", reverse = reverse, range = range, |
475 | 6x |
midpoint = midpoint, ...) |
476 |
} |
|
477 |
} |
|
478 | ||
479 |
#' @export |
|
480 |
#' @rdname scale_crameri_berlin |
|
481 |
scale_color_berlin <- scale_colour_berlin |
|
482 | ||
483 |
#' @export |
|
484 |
#' @rdname scale_crameri_berlin |
|
485 |
scale_fill_berlin <- function(..., reverse = FALSE, range = c(0, 1), |
|
486 |
midpoint = 0, discrete = FALSE, |
|
487 |
aesthetics = "fill") { |
|
488 | 4x |
if (discrete) { |
489 | ! |
scale_discrete(aesthetics, "berlin", reverse = reverse, ...) |
490 |
} else { |
|
491 | 4x |
scale_continuous(aesthetics, "berlin", reverse = reverse, range = range, |
492 | 4x |
midpoint = midpoint, ...) |
493 |
} |
|
494 |
} |
|
495 | ||
496 |
#' @export |
|
497 |
#' @rdname scale_crameri_berlin |
|
498 |
scale_edge_colour_berlin <- function(..., reverse = FALSE, range = c(0, 1), |
|
499 |
midpoint = 0, discrete = FALSE, |
|
500 |
aesthetics = "edge_colour") { |
|
501 | 6x |
if (discrete) { |
502 | ! |
scale_discrete(aesthetics, "berlin", reverse = reverse, ...) |
503 |
} else { |
|
504 | 6x |
scale_continuous(aesthetics, "berlin", guide = "edge_colourbar", |
505 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
506 |
} |
|
507 |
} |
|
508 | ||
509 |
#' @export |
|
510 |
#' @rdname scale_crameri_berlin |
|
511 |
scale_edge_color_berlin <- scale_edge_colour_berlin |
|
512 | ||
513 |
#' @export |
|
514 |
#' @rdname scale_crameri_berlin |
|
515 |
scale_edge_fill_berlin <- function(..., reverse = FALSE, range = c(0, 1), |
|
516 |
midpoint = 0, discrete = FALSE, |
|
517 |
aesthetics = "edge_fill") { |
|
518 | 4x |
if (discrete) { |
519 | ! |
scale_discrete(aesthetics, "berlin", reverse = reverse, ...) |
520 |
} else { |
|
521 | 4x |
scale_continuous(aesthetics, "berlin", guide = "edge_colourbar", |
522 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
523 |
} |
|
524 |
} |
|
525 | ||
526 |
## roma ------------------------------------------------------------------------ |
|
527 |
#' Fabio Crameri's *roma* Diverging Color Scheme |
|
528 |
#' |
|
529 |
#' @inheritParams scale_crameri_broc |
|
530 |
#' @inheritSection crameri Diverging Color Schemes |
|
531 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
532 |
#' @references |
|
533 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
534 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
535 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
536 |
#' |
|
537 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
538 |
#' science communication. *Nature Communications*, 11, 5444. |
|
539 |
#' \doi{10.1038/s41467-020-19160-7} |
|
540 |
#' @source |
|
541 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
542 |
#' \doi{10.5281/zenodo.4491293} |
|
543 |
#' @example inst/examples/ex-crameri-diverging.R |
|
544 |
#' @author N. Frerebeau |
|
545 |
#' @family diverging color schemes |
|
546 |
#' @family Fabio Crameri's color schemes |
|
547 |
#' @name scale_crameri_roma |
|
548 |
#' @rdname scale_crameri_roma |
|
549 |
NULL |
|
550 | ||
551 |
#' @export |
|
552 |
#' @rdname scale_crameri_roma |
|
553 |
scale_colour_roma <- function(..., reverse = FALSE, range = c(0, 1), |
|
554 |
midpoint = 0, discrete = FALSE, |
|
555 |
aesthetics = "colour") { |
|
556 | 6x |
if (discrete) { |
557 | ! |
scale_discrete(aesthetics, "roma", reverse = reverse, ...) |
558 |
} else { |
|
559 | 6x |
scale_continuous(aesthetics, "roma", reverse = reverse, range = range, |
560 | 6x |
midpoint = midpoint, ...) |
561 |
} |
|
562 |
} |
|
563 | ||
564 |
#' @export |
|
565 |
#' @rdname scale_crameri_roma |
|
566 |
scale_color_roma <- scale_colour_roma |
|
567 | ||
568 |
#' @export |
|
569 |
#' @rdname scale_crameri_roma |
|
570 |
scale_fill_roma <- function(..., reverse = FALSE, range = c(0, 1), |
|
571 |
midpoint = 0, discrete = FALSE, |
|
572 |
aesthetics = "fill") { |
|
573 | 4x |
if (discrete) { |
574 | ! |
scale_discrete(aesthetics, "roma", reverse = reverse, ...) |
575 |
} else { |
|
576 | 4x |
scale_continuous(aesthetics, "roma", reverse = reverse, range = range, |
577 | 4x |
midpoint = midpoint, ...) |
578 |
} |
|
579 |
} |
|
580 | ||
581 |
#' @export |
|
582 |
#' @rdname scale_crameri_roma |
|
583 |
scale_edge_colour_roma <- function(..., reverse = FALSE, range = c(0, 1), |
|
584 |
midpoint = 0, discrete = FALSE, |
|
585 |
aesthetics = "edge_colour") { |
|
586 | 6x |
if (discrete) { |
587 | ! |
scale_discrete(aesthetics, "roma", reverse = reverse, ...) |
588 |
} else { |
|
589 | 6x |
scale_continuous(aesthetics, "roma", guide = "edge_colourbar", |
590 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
591 |
} |
|
592 |
} |
|
593 | ||
594 |
#' @export |
|
595 |
#' @rdname scale_crameri_roma |
|
596 |
scale_edge_color_roma <- scale_edge_colour_roma |
|
597 | ||
598 |
#' @export |
|
599 |
#' @rdname scale_crameri_roma |
|
600 |
scale_edge_fill_roma <- function(..., reverse = FALSE, range = c(0, 1), |
|
601 |
midpoint = 0, discrete = FALSE, |
|
602 |
aesthetics = "edge_fill") { |
|
603 | 4x |
if (discrete) { |
604 | ! |
scale_discrete(aesthetics, "roma", reverse = reverse, ...) |
605 |
} else { |
|
606 | 4x |
scale_continuous(aesthetics, "roma", guide = "edge_colourbar", |
607 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
608 |
} |
|
609 |
} |
|
610 | ||
611 |
## bam ------------------------------------------------------------------------- |
|
612 |
#' Fabio Crameri's *bam* Diverging Color Scheme |
|
613 |
#' |
|
614 |
#' @inheritParams scale_crameri_broc |
|
615 |
#' @inheritSection crameri Diverging Color Schemes |
|
616 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
617 |
#' @references |
|
618 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
619 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
620 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
621 |
#' |
|
622 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
623 |
#' science communication. *Nature Communications*, 11, 5444. |
|
624 |
#' \doi{10.1038/s41467-020-19160-7} |
|
625 |
#' @source |
|
626 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
627 |
#' \doi{10.5281/zenodo.4491293} |
|
628 |
#' @example inst/examples/ex-crameri-diverging.R |
|
629 |
#' @author N. Frerebeau |
|
630 |
#' @family diverging color schemes |
|
631 |
#' @family Fabio Crameri's color schemes |
|
632 |
#' @name scale_crameri_bam |
|
633 |
#' @rdname scale_crameri_bam |
|
634 |
NULL |
|
635 | ||
636 |
#' @export |
|
637 |
#' @rdname scale_crameri_bam |
|
638 |
scale_colour_bam <- function(..., reverse = FALSE, range = c(0, 1), |
|
639 |
midpoint = 0, discrete = FALSE, |
|
640 |
aesthetics = "colour") { |
|
641 | 6x |
if (discrete) { |
642 | ! |
scale_discrete(aesthetics, "bam", reverse = reverse, ...) |
643 |
} else { |
|
644 | 6x |
scale_continuous(aesthetics, "bam", reverse = reverse, range = range, |
645 | 6x |
midpoint = midpoint, ...) |
646 |
} |
|
647 |
} |
|
648 | ||
649 |
#' @export |
|
650 |
#' @rdname scale_crameri_bam |
|
651 |
scale_color_bam <- scale_colour_bam |
|
652 | ||
653 |
#' @export |
|
654 |
#' @rdname scale_crameri_bam |
|
655 |
scale_fill_bam <- function(..., reverse = FALSE, range = c(0, 1), |
|
656 |
midpoint = 0, discrete = FALSE, |
|
657 |
aesthetics = "fill") { |
|
658 | 4x |
if (discrete) { |
659 | ! |
scale_discrete(aesthetics, "bam", reverse = reverse, ...) |
660 |
} else { |
|
661 | 4x |
scale_continuous(aesthetics, "bam", reverse = reverse, range = range, |
662 | 4x |
midpoint = midpoint, ...) |
663 |
} |
|
664 |
} |
|
665 | ||
666 |
#' @export |
|
667 |
#' @rdname scale_crameri_bam |
|
668 |
scale_edge_colour_bam <- function(..., reverse = FALSE, range = c(0, 1), |
|
669 |
midpoint = 0, discrete = FALSE, |
|
670 |
aesthetics = "edge_colour") { |
|
671 | 6x |
if (discrete) { |
672 | ! |
scale_discrete(aesthetics, "bam", reverse = reverse, ...) |
673 |
} else { |
|
674 | 6x |
scale_continuous(aesthetics, "bam", guide = "edge_colourbar", |
675 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
676 |
} |
|
677 |
} |
|
678 | ||
679 |
#' @export |
|
680 |
#' @rdname scale_crameri_bam |
|
681 |
scale_edge_color_bam <- scale_edge_colour_bam |
|
682 | ||
683 |
#' @export |
|
684 |
#' @rdname scale_crameri_bam |
|
685 |
scale_edge_fill_bam <- function(..., reverse = FALSE, range = c(0, 1), |
|
686 |
midpoint = 0, discrete = FALSE, |
|
687 |
aesthetics = "edge_fill") { |
|
688 | 4x |
if (discrete) { |
689 | ! |
scale_discrete(aesthetics, "bam", reverse = reverse, ...) |
690 |
} else { |
|
691 | 4x |
scale_continuous(aesthetics, "bam", guide = "edge_colourbar", |
692 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
693 |
} |
|
694 |
} |
|
695 | ||
696 |
## vanimo ---------------------------------------------------------------------- |
|
697 |
#' Fabio Crameri's *vanimo* Diverging Color Scheme |
|
698 |
#' |
|
699 |
#' @inheritParams scale_crameri_broc |
|
700 |
#' @inheritSection crameri Diverging Color Schemes |
|
701 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
702 |
#' @references |
|
703 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
704 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
705 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
706 |
#' |
|
707 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
708 |
#' science communication. *Nature Communications*, 11, 5444. |
|
709 |
#' \doi{10.1038/s41467-020-19160-7} |
|
710 |
#' @source |
|
711 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
712 |
#' \doi{10.5281/zenodo.4491293} |
|
713 |
#' @example inst/examples/ex-crameri-diverging.R |
|
714 |
#' @author N. Frerebeau |
|
715 |
#' @family diverging color schemes |
|
716 |
#' @family Fabio Crameri's color schemes |
|
717 |
#' @name scale_crameri_vanimo |
|
718 |
#' @rdname scale_crameri_vanimo |
|
719 |
NULL |
|
720 | ||
721 |
#' @export |
|
722 |
#' @rdname scale_crameri_vanimo |
|
723 |
scale_colour_vanimo <- function(..., reverse = FALSE, range = c(0, 1), |
|
724 |
midpoint = 0, discrete = FALSE, |
|
725 |
aesthetics = "colour") { |
|
726 | 6x |
if (discrete) { |
727 | ! |
scale_discrete(aesthetics, "vanimo", reverse = reverse, ...) |
728 |
} else { |
|
729 | 6x |
scale_continuous(aesthetics, "vanimo", reverse = reverse, range = range, |
730 | 6x |
midpoint = midpoint, ...) |
731 |
} |
|
732 |
} |
|
733 | ||
734 |
#' @export |
|
735 |
#' @rdname scale_crameri_vanimo |
|
736 |
scale_color_vanimo <- scale_colour_vanimo |
|
737 | ||
738 |
#' @export |
|
739 |
#' @rdname scale_crameri_vanimo |
|
740 |
scale_fill_vanimo <- function(..., reverse = FALSE, range = c(0, 1), |
|
741 |
midpoint = 0, discrete = FALSE, |
|
742 |
aesthetics = "fill") { |
|
743 | 4x |
if (discrete) { |
744 | ! |
scale_discrete(aesthetics, "vanimo", reverse = reverse, ...) |
745 |
} else { |
|
746 | 4x |
scale_continuous(aesthetics, "vanimo", reverse = reverse, range = range, |
747 | 4x |
midpoint = midpoint, ...) |
748 |
} |
|
749 |
} |
|
750 | ||
751 |
#' @export |
|
752 |
#' @rdname scale_crameri_vanimo |
|
753 |
scale_edge_colour_vanimo <- function(..., reverse = FALSE, range = c(0, 1), |
|
754 |
midpoint = 0, discrete = FALSE, |
|
755 |
aesthetics = "edge_colour") { |
|
756 | 6x |
if (discrete) { |
757 | ! |
scale_discrete(aesthetics, "vanimo", reverse = reverse, ...) |
758 |
} else { |
|
759 | 6x |
scale_continuous(aesthetics, "vanimo", guide = "edge_colourbar", |
760 | 6x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
761 |
} |
|
762 |
} |
|
763 | ||
764 |
#' @export |
|
765 |
#' @rdname scale_crameri_vanimo |
|
766 |
scale_edge_color_vanimo <- scale_edge_colour_vanimo |
|
767 | ||
768 |
#' @export |
|
769 |
#' @rdname scale_crameri_vanimo |
|
770 |
scale_edge_fill_vanimo <- function(..., reverse = FALSE, range = c(0, 1), |
|
771 |
midpoint = 0, discrete = FALSE, |
|
772 |
aesthetics = "edge_fill") { |
|
773 | 4x |
if (discrete) { |
774 | ! |
scale_discrete(aesthetics, "vanimo", reverse = reverse, ...) |
775 |
} else { |
|
776 | 4x |
scale_continuous(aesthetics, "vanimo", guide = "edge_colourbar", |
777 | 4x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
778 |
} |
|
779 |
} |
|
780 | ||
781 |
# Sequential =================================================================== |
|
782 |
## batlow ---------------------------------------------------------------------- |
|
783 |
#' Fabio Crameri's *batlow* Sequential Color Scheme |
|
784 |
#' |
|
785 |
#' @param ... Arguments passed to [ggplot2::continuous_scale()]. |
|
786 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
787 |
#' vector of colors be reversed? |
|
788 |
#' @param range A length-two [`numeric`] vector specifying the |
|
789 |
#' fraction of the scheme's color domain to keep. |
|
790 |
#' @param aesthetics A [`character`] string or vector of character |
|
791 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
792 |
#' @param discrete A [`logical`] scalar: should the color scheme be |
|
793 |
#' used as a discrete scale? |
|
794 |
#' @inheritSection crameri Sequential Color Schemes |
|
795 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
796 |
#' @references |
|
797 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
798 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
799 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
800 |
#' |
|
801 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
802 |
#' science communication. *Nature Communications*, 11, 5444. |
|
803 |
#' \doi{10.1038/s41467-020-19160-7} |
|
804 |
#' @source |
|
805 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
806 |
#' \doi{10.5281/zenodo.4491293} |
|
807 |
#' @example inst/examples/ex-crameri-sequential.R |
|
808 |
#' @author N. Frerebeau |
|
809 |
#' @family sequential color schemes |
|
810 |
#' @family Fabio Crameri's color schemes |
|
811 |
#' @name scale_crameri_batlow |
|
812 |
#' @rdname scale_crameri_batlow |
|
813 |
NULL |
|
814 | ||
815 |
#' @export |
|
816 |
#' @rdname scale_crameri_batlow |
|
817 |
scale_colour_batlow <- function(..., reverse = FALSE, range = c(0, 1), |
|
818 |
discrete = FALSE, aesthetics = "colour") { |
|
819 | 5x |
if (discrete) { |
820 | 1x |
scale_discrete(aesthetics, "batlow", reverse = reverse, ...) |
821 |
} else { |
|
822 | 4x |
scale_continuous(aesthetics, "batlow", reverse = reverse, |
823 | 4x |
range = range, ...) |
824 |
} |
|
825 |
} |
|
826 | ||
827 |
#' @export |
|
828 |
#' @rdname scale_crameri_batlow |
|
829 |
scale_color_batlow <- scale_colour_batlow |
|
830 | ||
831 |
#' @export |
|
832 |
#' @rdname scale_crameri_batlow |
|
833 |
scale_fill_batlow <- function(..., reverse = FALSE, range = c(0, 1), |
|
834 |
discrete = FALSE, aesthetics = "fill") { |
|
835 | 3x |
if (discrete) { |
836 | 1x |
scale_discrete(aesthetics, "batlow", reverse = reverse, ...) |
837 |
} else { |
|
838 | 2x |
scale_continuous(aesthetics, "batlow", reverse = reverse, |
839 | 2x |
range = range, ...) |
840 |
} |
|
841 |
} |
|
842 | ||
843 |
#' @export |
|
844 |
#' @rdname scale_crameri_batlow |
|
845 |
scale_edge_colour_batlow <- function(..., reverse = FALSE, range = c(0, 1), |
|
846 |
discrete = FALSE, |
|
847 |
aesthetics = "edge_colour") { |
|
848 | 5x |
if (discrete) { |
849 | 1x |
scale_discrete(aesthetics, "batlow", reverse = reverse, ...) |
850 |
} else { |
|
851 | 4x |
scale_continuous(aesthetics, "batlow", guide = "edge_colourbar", |
852 | 4x |
reverse = reverse, range = range, ...) |
853 |
} |
|
854 |
} |
|
855 | ||
856 |
#' @export |
|
857 |
#' @rdname scale_crameri_batlow |
|
858 |
scale_edge_color_batlow <- scale_edge_colour_batlow |
|
859 | ||
860 |
#' @export |
|
861 |
#' @rdname scale_crameri_batlow |
|
862 |
scale_edge_fill_batlow <- function(..., reverse = FALSE, range = c(0, 1), |
|
863 |
discrete = FALSE, |
|
864 |
aesthetics = "edge_fill") { |
|
865 | 3x |
if (discrete) { |
866 | 1x |
scale_discrete(aesthetics, "batlow", reverse = reverse, ...) |
867 |
} else { |
|
868 | 2x |
scale_continuous(aesthetics, "batlow", guide = "edge_colourbar", |
869 | 2x |
reverse = reverse, range = range, ...) |
870 |
} |
|
871 |
} |
|
872 | ||
873 |
## batlowW --------------------------------------------------------------------- |
|
874 |
#' Fabio Crameri's *batlowW* Sequential Color Scheme |
|
875 |
#' |
|
876 |
#' @inheritParams scale_crameri_batlow |
|
877 |
#' @inheritSection crameri Sequential Color Schemes |
|
878 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
879 |
#' @references |
|
880 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
881 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
882 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
883 |
#' |
|
884 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
885 |
#' science communication. *Nature Communications*, 11, 5444. |
|
886 |
#' \doi{10.1038/s41467-020-19160-7} |
|
887 |
#' @source |
|
888 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
889 |
#' \doi{10.5281/zenodo.4491293} |
|
890 |
#' @example inst/examples/ex-crameri-sequential.R |
|
891 |
#' @author N. Frerebeau |
|
892 |
#' @family sequential color schemes |
|
893 |
#' @family Fabio Crameri's color schemes |
|
894 |
#' @name scale_crameri_batlowW |
|
895 |
#' @rdname scale_crameri_batlowW |
|
896 |
NULL |
|
897 | ||
898 |
#' @export |
|
899 |
#' @rdname scale_crameri_batlowW |
|
900 |
scale_colour_batlowW <- function(..., reverse = FALSE, range = c(0, 1), |
|
901 |
discrete = FALSE, aesthetics = "colour") { |
|
902 | 5x |
if (discrete) { |
903 | 1x |
scale_discrete(aesthetics, "batlowW", reverse = reverse, ...) |
904 |
} else { |
|
905 | 4x |
scale_continuous(aesthetics, "batlowW", reverse = reverse, |
906 | 4x |
range = range, ...) |
907 |
} |
|
908 |
} |
|
909 | ||
910 |
#' @export |
|
911 |
#' @rdname scale_crameri_batlowW |
|
912 |
scale_color_batlowW <- scale_colour_batlowW |
|
913 | ||
914 |
#' @export |
|
915 |
#' @rdname scale_crameri_batlowW |
|
916 |
scale_fill_batlowW <- function(..., reverse = FALSE, range = c(0, 1), |
|
917 |
discrete = FALSE, aesthetics = "fill") { |
|
918 | 3x |
if (discrete) { |
919 | 1x |
scale_discrete(aesthetics, "batlowW", reverse = reverse, ...) |
920 |
} else { |
|
921 | 2x |
scale_continuous(aesthetics, "batlowW", reverse = reverse, |
922 | 2x |
range = range, ...) |
923 |
} |
|
924 |
} |
|
925 | ||
926 |
#' @export |
|
927 |
#' @rdname scale_crameri_batlowW |
|
928 |
scale_edge_colour_batlowW <- function(..., reverse = FALSE, range = c(0, 1), |
|
929 |
discrete = FALSE, |
|
930 |
aesthetics = "edge_colour") { |
|
931 | 5x |
if (discrete) { |
932 | 1x |
scale_discrete(aesthetics, "batlowW", reverse = reverse, ...) |
933 |
} else { |
|
934 | 4x |
scale_continuous(aesthetics, "batlowW", guide = "edge_colourbar", |
935 | 4x |
reverse = reverse, range = range, ...) |
936 |
} |
|
937 |
} |
|
938 | ||
939 |
#' @export |
|
940 |
#' @rdname scale_crameri_batlowW |
|
941 |
scale_edge_color_batlowW <- scale_edge_colour_batlowW |
|
942 | ||
943 |
#' @export |
|
944 |
#' @rdname scale_crameri_batlowW |
|
945 |
scale_edge_fill_batlowW <- function(..., reverse = FALSE, range = c(0, 1), |
|
946 |
discrete = FALSE, |
|
947 |
aesthetics = "edge_fill") { |
|
948 | 3x |
if (discrete) { |
949 | 1x |
scale_discrete(aesthetics, "batlowW", reverse = reverse, ...) |
950 |
} else { |
|
951 | 2x |
scale_continuous(aesthetics, "batlowW", guide = "edge_colourbar", |
952 | 2x |
reverse = reverse, range = range, ...) |
953 |
} |
|
954 |
} |
|
955 | ||
956 |
## batlowK --------------------------------------------------------------------- |
|
957 |
#' Fabio Crameri's *batlowK* Sequential Color Scheme |
|
958 |
#' |
|
959 |
#' @inheritParams scale_crameri_batlow |
|
960 |
#' @inheritSection crameri Sequential Color Schemes |
|
961 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
962 |
#' @references |
|
963 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
964 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
965 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
966 |
#' |
|
967 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
968 |
#' science communication. *Nature Communications*, 11, 5444. |
|
969 |
#' \doi{10.1038/s41467-020-19160-7} |
|
970 |
#' @source |
|
971 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
972 |
#' \doi{10.5281/zenodo.4491293} |
|
973 |
#' @example inst/examples/ex-crameri-sequential.R |
|
974 |
#' @author N. Frerebeau |
|
975 |
#' @family sequential color schemes |
|
976 |
#' @family Fabio Crameri's color schemes |
|
977 |
#' @name scale_crameri_batlowK |
|
978 |
#' @rdname scale_crameri_batlowK |
|
979 |
NULL |
|
980 | ||
981 |
#' @export |
|
982 |
#' @rdname scale_crameri_batlowK |
|
983 |
scale_colour_batlowK <- function(..., reverse = FALSE, range = c(0, 1), |
|
984 |
discrete = FALSE, aesthetics = "colour") { |
|
985 | 5x |
if (discrete) { |
986 | 1x |
scale_discrete(aesthetics, "batlowK", reverse = reverse, ...) |
987 |
} else { |
|
988 | 4x |
scale_continuous(aesthetics, "batlowK", reverse = reverse, |
989 | 4x |
range = range, ...) |
990 |
} |
|
991 |
} |
|
992 | ||
993 |
#' @export |
|
994 |
#' @rdname scale_crameri_batlowK |
|
995 |
scale_color_batlowK <- scale_colour_batlowK |
|
996 | ||
997 |
#' @export |
|
998 |
#' @rdname scale_crameri_batlowK |
|
999 |
scale_fill_batlowK <- function(..., reverse = FALSE, range = c(0, 1), |
|
1000 |
discrete = FALSE, aesthetics = "fill") { |
|
1001 | 3x |
if (discrete) { |
1002 | 1x |
scale_discrete(aesthetics, "batlowK", reverse = reverse, ...) |
1003 |
} else { |
|
1004 | 2x |
scale_continuous(aesthetics, "batlowK", reverse = reverse, |
1005 | 2x |
range = range, ...) |
1006 |
} |
|
1007 |
} |
|
1008 | ||
1009 |
#' @export |
|
1010 |
#' @rdname scale_crameri_batlowK |
|
1011 |
scale_edge_colour_batlowK <- function(..., reverse = FALSE, range = c(0, 1), |
|
1012 |
discrete = FALSE, |
|
1013 |
aesthetics = "edge_colour") { |
|
1014 | 5x |
if (discrete) { |
1015 | 1x |
scale_discrete(aesthetics, "batlowK", reverse = reverse, ...) |
1016 |
} else { |
|
1017 | 4x |
scale_continuous(aesthetics, "batlowK", guide = "edge_colourbar", |
1018 | 4x |
reverse = reverse, range = range, ...) |
1019 |
} |
|
1020 |
} |
|
1021 | ||
1022 |
#' @export |
|
1023 |
#' @rdname scale_crameri_batlowK |
|
1024 |
scale_edge_color_batlowK <- scale_edge_colour_batlowK |
|
1025 | ||
1026 |
#' @export |
|
1027 |
#' @rdname scale_crameri_batlowK |
|
1028 |
scale_edge_fill_batlowK <- function(..., reverse = FALSE, range = c(0, 1), |
|
1029 |
discrete = FALSE, |
|
1030 |
aesthetics = "edge_fill") { |
|
1031 | 3x |
if (discrete) { |
1032 | 1x |
scale_discrete(aesthetics, "batlowK", reverse = reverse, ...) |
1033 |
} else { |
|
1034 | 2x |
scale_continuous(aesthetics, "batlowK", guide = "edge_colourbar", |
1035 | 2x |
reverse = reverse, range = range, ...) |
1036 |
} |
|
1037 |
} |
|
1038 | ||
1039 |
## devon ----------------------------------------------------------------------- |
|
1040 |
#' Fabio Crameri's *devon* Sequential Color Scheme |
|
1041 |
#' |
|
1042 |
#' @inheritParams scale_crameri_batlow |
|
1043 |
#' @inheritSection crameri Sequential Color Schemes |
|
1044 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1045 |
#' @references |
|
1046 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1047 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1048 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1049 |
#' |
|
1050 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1051 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1052 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1053 |
#' @source |
|
1054 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1055 |
#' \doi{10.5281/zenodo.4491293} |
|
1056 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1057 |
#' @author N. Frerebeau |
|
1058 |
#' @family sequential color schemes |
|
1059 |
#' @family Fabio Crameri's color schemes |
|
1060 |
#' @name scale_crameri_devon |
|
1061 |
#' @rdname scale_crameri_devon |
|
1062 |
NULL |
|
1063 | ||
1064 |
#' @export |
|
1065 |
#' @rdname scale_crameri_devon |
|
1066 |
scale_colour_devon <- function(..., reverse = FALSE, range = c(0, 1), |
|
1067 |
discrete = FALSE, aesthetics = "colour") { |
|
1068 | 5x |
if (discrete) { |
1069 | 1x |
scale_discrete(aesthetics, "devon", reverse = reverse, ...) |
1070 |
} else { |
|
1071 | 4x |
scale_continuous(aesthetics, "devon", reverse = reverse, |
1072 | 4x |
range = range, ...) |
1073 |
} |
|
1074 |
} |
|
1075 | ||
1076 |
#' @export |
|
1077 |
#' @rdname scale_crameri_devon |
|
1078 |
scale_color_devon <- scale_colour_devon |
|
1079 | ||
1080 |
#' @export |
|
1081 |
#' @rdname scale_crameri_devon |
|
1082 |
scale_fill_devon <- function(..., reverse = FALSE, range = c(0, 1), |
|
1083 |
discrete = FALSE, aesthetics = "fill") { |
|
1084 | 3x |
if (discrete) { |
1085 | 1x |
scale_discrete(aesthetics, "devon", reverse = reverse, ...) |
1086 |
} else { |
|
1087 | 2x |
scale_continuous(aesthetics, "devon", reverse = reverse, |
1088 | 2x |
range = range, ...) |
1089 |
} |
|
1090 |
} |
|
1091 | ||
1092 |
#' @export |
|
1093 |
#' @rdname scale_crameri_devon |
|
1094 |
scale_edge_colour_devon <- function(..., reverse = FALSE, range = c(0, 1), |
|
1095 |
discrete = FALSE, |
|
1096 |
aesthetics = "edge_colour") { |
|
1097 | 5x |
if (discrete) { |
1098 | 1x |
scale_discrete(aesthetics, "devon", reverse = reverse, ...) |
1099 |
} else { |
|
1100 | 4x |
scale_continuous(aesthetics, "devon", guide = "edge_colourbar", |
1101 | 4x |
reverse = reverse, range = range, ...) |
1102 |
} |
|
1103 |
} |
|
1104 | ||
1105 |
#' @export |
|
1106 |
#' @rdname scale_crameri_devon |
|
1107 |
scale_edge_color_devon <- scale_edge_colour_devon |
|
1108 | ||
1109 |
#' @export |
|
1110 |
#' @rdname scale_crameri_devon |
|
1111 |
scale_edge_fill_devon <- function(..., reverse = FALSE, range = c(0, 1), |
|
1112 |
discrete = FALSE, |
|
1113 |
aesthetics = "edge_fill") { |
|
1114 | 3x |
if (discrete) { |
1115 | 1x |
scale_discrete(aesthetics, "devon", reverse = reverse, ...) |
1116 |
} else { |
|
1117 | 2x |
scale_continuous(aesthetics, "devon", guide = "edge_colourbar", |
1118 | 2x |
reverse = reverse, range = range, ...) |
1119 |
} |
|
1120 |
} |
|
1121 | ||
1122 |
## lajolla --------------------------------------------------------------------- |
|
1123 |
#' Fabio Crameri's *lajolla* Sequential Color Scheme |
|
1124 |
#' |
|
1125 |
#' @inheritParams scale_crameri_batlow |
|
1126 |
#' @inheritSection crameri Sequential Color Schemes |
|
1127 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1128 |
#' @references |
|
1129 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1130 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1131 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1132 |
#' |
|
1133 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1134 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1135 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1136 |
#' @source |
|
1137 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1138 |
#' \doi{10.5281/zenodo.4491293} |
|
1139 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1140 |
#' @author N. Frerebeau |
|
1141 |
#' @family sequential color schemes |
|
1142 |
#' @family Fabio Crameri's color schemes |
|
1143 |
#' @name scale_crameri_lajolla |
|
1144 |
#' @rdname scale_crameri_lajolla |
|
1145 |
NULL |
|
1146 | ||
1147 |
#' @export |
|
1148 |
#' @rdname scale_crameri_lajolla |
|
1149 |
scale_colour_lajolla <- function(..., reverse = FALSE, range = c(0, 1), |
|
1150 |
discrete = FALSE, aesthetics = "colour") { |
|
1151 | 5x |
if (discrete) { |
1152 | 1x |
scale_discrete(aesthetics, "lajolla", reverse = reverse, ...) |
1153 |
} else { |
|
1154 | 4x |
scale_continuous(aesthetics, "lajolla", reverse = reverse, |
1155 | 4x |
range = range, ...) |
1156 |
} |
|
1157 |
} |
|
1158 | ||
1159 |
#' @export |
|
1160 |
#' @rdname scale_crameri_lajolla |
|
1161 |
scale_color_lajolla <- scale_colour_lajolla |
|
1162 | ||
1163 |
#' @export |
|
1164 |
#' @rdname scale_crameri_lajolla |
|
1165 |
scale_fill_lajolla <- function(..., reverse = FALSE, range = c(0, 1), |
|
1166 |
discrete = FALSE, aesthetics = "fill") { |
|
1167 | 3x |
if (discrete) { |
1168 | 1x |
scale_discrete(aesthetics, "lajolla", reverse = reverse, ...) |
1169 |
} else { |
|
1170 | 2x |
scale_continuous(aesthetics, "lajolla", reverse = reverse, |
1171 | 2x |
range = range, ...) |
1172 |
} |
|
1173 |
} |
|
1174 | ||
1175 |
#' @export |
|
1176 |
#' @rdname scale_crameri_lajolla |
|
1177 |
scale_edge_colour_lajolla <- function(..., reverse = FALSE, range = c(0, 1), |
|
1178 |
discrete = FALSE, |
|
1179 |
aesthetics = "edge_colour") { |
|
1180 | 5x |
if (discrete) { |
1181 | 1x |
scale_discrete(aesthetics, "lajolla", reverse = reverse, ...) |
1182 |
} else { |
|
1183 | 4x |
scale_continuous(aesthetics, "lajolla", guide = "edge_colourbar", |
1184 | 4x |
reverse = reverse, range = range, ...) |
1185 |
} |
|
1186 |
} |
|
1187 | ||
1188 |
#' @export |
|
1189 |
#' @rdname scale_crameri_lajolla |
|
1190 |
scale_edge_color_lajolla <- scale_edge_colour_lajolla |
|
1191 | ||
1192 |
#' @export |
|
1193 |
#' @rdname scale_crameri_lajolla |
|
1194 |
scale_edge_fill_lajolla <- function(..., reverse = FALSE, range = c(0, 1), |
|
1195 |
discrete = FALSE, |
|
1196 |
aesthetics = "edge_fill") { |
|
1197 | 3x |
if (discrete) { |
1198 | 1x |
scale_discrete(aesthetics, "lajolla", reverse = reverse, ...) |
1199 |
} else { |
|
1200 | 2x |
scale_continuous(aesthetics, "lajolla", guide = "edge_colourbar", |
1201 | 2x |
reverse = reverse, range = range, ...) |
1202 |
} |
|
1203 |
} |
|
1204 | ||
1205 |
## bamako ---------------------------------------------------------------------- |
|
1206 |
#' Fabio Crameri's *bamako* Sequential Color Scheme |
|
1207 |
#' |
|
1208 |
#' @inheritParams scale_crameri_batlow |
|
1209 |
#' @inheritSection crameri Sequential Color Schemes |
|
1210 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1211 |
#' @references |
|
1212 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1213 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1214 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1215 |
#' |
|
1216 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1217 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1218 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1219 |
#' @source |
|
1220 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1221 |
#' \doi{10.5281/zenodo.4491293} |
|
1222 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1223 |
#' @author N. Frerebeau |
|
1224 |
#' @family sequential color schemes |
|
1225 |
#' @family Fabio Crameri's color schemes |
|
1226 |
#' @name scale_crameri_bamako |
|
1227 |
#' @rdname scale_crameri_bamako |
|
1228 |
NULL |
|
1229 | ||
1230 |
#' @export |
|
1231 |
#' @rdname scale_crameri_bamako |
|
1232 |
scale_colour_bamako <- function(..., reverse = FALSE, range = c(0, 1), |
|
1233 |
discrete = FALSE, aesthetics = "colour") { |
|
1234 | 5x |
if (discrete) { |
1235 | 1x |
scale_discrete(aesthetics, "bamako", reverse = reverse, ...) |
1236 |
} else { |
|
1237 | 4x |
scale_continuous(aesthetics, "bamako", reverse = reverse, |
1238 | 4x |
range = range, ...) |
1239 |
} |
|
1240 |
} |
|
1241 | ||
1242 |
#' @export |
|
1243 |
#' @rdname scale_crameri_bamako |
|
1244 |
scale_color_bamako <- scale_colour_bamako |
|
1245 | ||
1246 |
#' @export |
|
1247 |
#' @rdname scale_crameri_bamako |
|
1248 |
scale_fill_bamako <- function(..., reverse = FALSE, range = c(0, 1), |
|
1249 |
discrete = FALSE, aesthetics = "fill") { |
|
1250 | 3x |
if (discrete) { |
1251 | 1x |
scale_discrete(aesthetics, "bamako", reverse = reverse, ...) |
1252 |
} else { |
|
1253 | 2x |
scale_continuous(aesthetics, "bamako", reverse = reverse, |
1254 | 2x |
range = range, ...) |
1255 |
} |
|
1256 |
} |
|
1257 | ||
1258 |
#' @export |
|
1259 |
#' @rdname scale_crameri_bamako |
|
1260 |
scale_edge_colour_bamako <- function(..., reverse = FALSE, range = c(0, 1), |
|
1261 |
discrete = FALSE, |
|
1262 |
aesthetics = "edge_colour") { |
|
1263 | 5x |
if (discrete) { |
1264 | 1x |
scale_discrete(aesthetics, "bamako", reverse = reverse, ...) |
1265 |
} else { |
|
1266 | 4x |
scale_continuous(aesthetics, "bamako", guide = "edge_colourbar", |
1267 | 4x |
reverse = reverse, range = range, ...) |
1268 |
} |
|
1269 |
} |
|
1270 | ||
1271 |
#' @export |
|
1272 |
#' @rdname scale_crameri_bamako |
|
1273 |
scale_edge_color_bamako <- scale_edge_colour_bamako |
|
1274 | ||
1275 |
#' @export |
|
1276 |
#' @rdname scale_crameri_bamako |
|
1277 |
scale_edge_fill_bamako <- function(..., reverse = FALSE, range = c(0, 1), |
|
1278 |
discrete = FALSE, |
|
1279 |
aesthetics = "edge_fill") { |
|
1280 | 3x |
if (discrete) { |
1281 | 1x |
scale_discrete(aesthetics, "bamako", reverse = reverse, ...) |
1282 |
} else { |
|
1283 | 2x |
scale_continuous(aesthetics, "bamako", guide = "edge_colourbar", |
1284 | 2x |
reverse = reverse, range = range, ...) |
1285 |
} |
|
1286 |
} |
|
1287 | ||
1288 |
## davos ----------------------------------------------------------------------- |
|
1289 |
#' Fabio Crameri's *davos* Sequential Color Scheme |
|
1290 |
#' |
|
1291 |
#' @inheritParams scale_crameri_batlow |
|
1292 |
#' @inheritSection crameri Sequential Color Schemes |
|
1293 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1294 |
#' @references |
|
1295 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1296 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1297 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1298 |
#' |
|
1299 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1300 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1301 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1302 |
#' @source |
|
1303 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1304 |
#' \doi{10.5281/zenodo.4491293} |
|
1305 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1306 |
#' @author N. Frerebeau |
|
1307 |
#' @family sequential color schemes |
|
1308 |
#' @family Fabio Crameri's color schemes |
|
1309 |
#' @name scale_crameri_davos |
|
1310 |
#' @rdname scale_crameri_davos |
|
1311 |
NULL |
|
1312 | ||
1313 |
#' @export |
|
1314 |
#' @rdname scale_crameri_davos |
|
1315 |
scale_colour_davos <- function(..., reverse = FALSE, range = c(0, 1), |
|
1316 |
discrete = FALSE, aesthetics = "colour") { |
|
1317 | 5x |
if (discrete) { |
1318 | 1x |
scale_discrete(aesthetics, "davos", reverse = reverse, ...) |
1319 |
} else { |
|
1320 | 4x |
scale_continuous(aesthetics, "davos", reverse = reverse, |
1321 | 4x |
range = range, ...) |
1322 |
} |
|
1323 |
} |
|
1324 | ||
1325 |
#' @export |
|
1326 |
#' @rdname scale_crameri_davos |
|
1327 |
scale_color_davos <- scale_colour_davos |
|
1328 | ||
1329 |
#' @export |
|
1330 |
#' @rdname scale_crameri_davos |
|
1331 |
scale_fill_davos <- function(..., reverse = FALSE, range = c(0, 1), |
|
1332 |
discrete = FALSE, aesthetics = "fill") { |
|
1333 | 3x |
if (discrete) { |
1334 | 1x |
scale_discrete(aesthetics, "davos", reverse = reverse, ...) |
1335 |
} else { |
|
1336 | 2x |
scale_continuous(aesthetics, "davos", reverse = reverse, |
1337 | 2x |
range = range, ...) |
1338 |
} |
|
1339 |
} |
|
1340 | ||
1341 |
#' @export |
|
1342 |
#' @rdname scale_crameri_davos |
|
1343 |
scale_edge_colour_davos <- function(..., reverse = FALSE, range = c(0, 1), |
|
1344 |
discrete = FALSE, |
|
1345 |
aesthetics = "edge_colour") { |
|
1346 | 5x |
if (discrete) { |
1347 | 1x |
scale_discrete(aesthetics, "davos", reverse = reverse, ...) |
1348 |
} else { |
|
1349 | 4x |
scale_continuous(aesthetics, "davos", guide = "edge_colourbar", |
1350 | 4x |
reverse = reverse, range = range, ...) |
1351 |
} |
|
1352 |
} |
|
1353 | ||
1354 |
#' @export |
|
1355 |
#' @rdname scale_crameri_davos |
|
1356 |
scale_edge_color_davos <- scale_edge_colour_davos |
|
1357 | ||
1358 |
#' @export |
|
1359 |
#' @rdname scale_crameri_davos |
|
1360 |
scale_edge_fill_davos <- function(..., reverse = FALSE, range = c(0, 1), |
|
1361 |
discrete = FALSE, |
|
1362 |
aesthetics = "edge_fill") { |
|
1363 | 3x |
if (discrete) { |
1364 | 1x |
scale_discrete(aesthetics, "davos", reverse = reverse, ...) |
1365 |
} else { |
|
1366 | 2x |
scale_continuous(aesthetics, "davos", guide = "edge_colourbar", |
1367 | 2x |
reverse = reverse, range = range, ...) |
1368 |
} |
|
1369 |
} |
|
1370 | ||
1371 |
## bilbao ---------------------------------------------------------------------- |
|
1372 |
#' Fabio Crameri's *bilbao* Sequential Color Scheme |
|
1373 |
#' |
|
1374 |
#' @inheritParams scale_crameri_batlow |
|
1375 |
#' @inheritSection crameri Sequential Color Schemes |
|
1376 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1377 |
#' @references |
|
1378 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1379 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1380 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1381 |
#' |
|
1382 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1383 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1384 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1385 |
#' @source |
|
1386 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1387 |
#' \doi{10.5281/zenodo.4491293} |
|
1388 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1389 |
#' @author N. Frerebeau |
|
1390 |
#' @family sequential color schemes |
|
1391 |
#' @family Fabio Crameri's color schemes |
|
1392 |
#' @name scale_crameri_bilbao |
|
1393 |
#' @rdname scale_crameri_bilbao |
|
1394 |
NULL |
|
1395 | ||
1396 |
#' @export |
|
1397 |
#' @rdname scale_crameri_bilbao |
|
1398 |
scale_colour_bilbao <- function(..., reverse = FALSE, range = c(0, 1), |
|
1399 |
discrete = FALSE, aesthetics = "colour") { |
|
1400 | 5x |
if (discrete) { |
1401 | 1x |
scale_discrete(aesthetics, "bilbao", reverse = reverse, ...) |
1402 |
} else { |
|
1403 | 4x |
scale_continuous(aesthetics, "bilbao", reverse = reverse, |
1404 | 4x |
range = range, ...) |
1405 |
} |
|
1406 |
} |
|
1407 | ||
1408 |
#' @export |
|
1409 |
#' @rdname scale_crameri_bilbao |
|
1410 |
scale_color_bilbao <- scale_colour_bilbao |
|
1411 | ||
1412 |
#' @export |
|
1413 |
#' @rdname scale_crameri_bilbao |
|
1414 |
scale_fill_bilbao <- function(..., reverse = FALSE, range = c(0, 1), |
|
1415 |
discrete = FALSE, aesthetics = "fill") { |
|
1416 | 3x |
if (discrete) { |
1417 | 1x |
scale_discrete(aesthetics, "bilbao", reverse = reverse, ...) |
1418 |
} else { |
|
1419 | 2x |
scale_continuous(aesthetics, "bilbao", reverse = reverse, |
1420 | 2x |
range = range, ...) |
1421 |
} |
|
1422 |
} |
|
1423 | ||
1424 |
#' @export |
|
1425 |
#' @rdname scale_crameri_bilbao |
|
1426 |
scale_edge_colour_bilbao <- function(..., reverse = FALSE, range = c(0, 1), |
|
1427 |
discrete = FALSE, |
|
1428 |
aesthetics = "edge_colour") { |
|
1429 | 5x |
if (discrete) { |
1430 | 1x |
scale_discrete(aesthetics, "bilbao", reverse = reverse, ...) |
1431 |
} else { |
|
1432 | 4x |
scale_continuous(aesthetics, "bilbao", guide = "edge_colourbar", |
1433 | 4x |
reverse = reverse, range = range, ...) |
1434 |
} |
|
1435 |
} |
|
1436 | ||
1437 |
#' @export |
|
1438 |
#' @rdname scale_crameri_bilbao |
|
1439 |
scale_edge_color_bilbao <- scale_edge_colour_bilbao |
|
1440 | ||
1441 |
#' @export |
|
1442 |
#' @rdname scale_crameri_bilbao |
|
1443 |
scale_edge_fill_bilbao <- function(..., reverse = FALSE, range = c(0, 1), |
|
1444 |
discrete = FALSE, |
|
1445 |
aesthetics = "edge_fill") { |
|
1446 | 3x |
if (discrete) { |
1447 | 1x |
scale_discrete(aesthetics, "bilbao", reverse = reverse, ...) |
1448 |
} else { |
|
1449 | 2x |
scale_continuous(aesthetics, "bilbao", guide = "edge_colourbar", |
1450 | 2x |
reverse = reverse, range = range, ...) |
1451 |
} |
|
1452 |
} |
|
1453 | ||
1454 |
## nuuk ------------------------------------------------------------------------ |
|
1455 |
#' Fabio Crameri's *nuuk* Sequential Color Scheme |
|
1456 |
#' |
|
1457 |
#' @inheritParams scale_crameri_batlow |
|
1458 |
#' @inheritSection crameri Sequential Color Schemes |
|
1459 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1460 |
#' @references |
|
1461 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1462 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1463 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1464 |
#' |
|
1465 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1466 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1467 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1468 |
#' @source |
|
1469 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1470 |
#' \doi{10.5281/zenodo.4491293} |
|
1471 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1472 |
#' @author N. Frerebeau |
|
1473 |
#' @family sequential color schemes |
|
1474 |
#' @family Fabio Crameri's color schemes |
|
1475 |
#' @name scale_crameri_nuuk |
|
1476 |
#' @rdname scale_crameri_nuuk |
|
1477 |
NULL |
|
1478 | ||
1479 |
#' @export |
|
1480 |
#' @rdname scale_crameri_nuuk |
|
1481 |
scale_colour_nuuk <- function(..., reverse = FALSE, range = c(0, 1), |
|
1482 |
discrete = FALSE, aesthetics = "colour") { |
|
1483 | 5x |
if (discrete) { |
1484 | 1x |
scale_discrete(aesthetics, "nuuk", reverse = reverse, ...) |
1485 |
} else { |
|
1486 | 4x |
scale_continuous(aesthetics, "nuuk", reverse = reverse, |
1487 | 4x |
range = range, ...) |
1488 |
} |
|
1489 |
} |
|
1490 | ||
1491 |
#' @export |
|
1492 |
#' @rdname scale_crameri_nuuk |
|
1493 |
scale_color_nuuk <- scale_colour_nuuk |
|
1494 | ||
1495 |
#' @export |
|
1496 |
#' @rdname scale_crameri_nuuk |
|
1497 |
scale_fill_nuuk <- function(..., reverse = FALSE, range = c(0, 1), |
|
1498 |
discrete = FALSE, aesthetics = "fill") { |
|
1499 | 3x |
if (discrete) { |
1500 | 1x |
scale_discrete(aesthetics, "nuuk", reverse = reverse, ...) |
1501 |
} else { |
|
1502 | 2x |
scale_continuous(aesthetics, "nuuk", reverse = reverse, |
1503 | 2x |
range = range, ...) |
1504 |
} |
|
1505 |
} |
|
1506 | ||
1507 |
#' @export |
|
1508 |
#' @rdname scale_crameri_nuuk |
|
1509 |
scale_edge_colour_nuuk <- function(..., reverse = FALSE, range = c(0, 1), |
|
1510 |
discrete = FALSE, |
|
1511 |
aesthetics = "edge_colour") { |
|
1512 | 5x |
if (discrete) { |
1513 | 1x |
scale_discrete(aesthetics, "nuuk", reverse = reverse, ...) |
1514 |
} else { |
|
1515 | 4x |
scale_continuous(aesthetics, "nuuk", guide = "edge_colourbar", |
1516 | 4x |
reverse = reverse, range = range, ...) |
1517 |
} |
|
1518 |
} |
|
1519 | ||
1520 |
#' @export |
|
1521 |
#' @rdname scale_crameri_nuuk |
|
1522 |
scale_edge_color_nuuk <- scale_edge_colour_nuuk |
|
1523 | ||
1524 |
#' @export |
|
1525 |
#' @rdname scale_crameri_nuuk |
|
1526 |
scale_edge_fill_nuuk <- function(..., reverse = FALSE, range = c(0, 1), |
|
1527 |
discrete = FALSE, |
|
1528 |
aesthetics = "edge_fill") { |
|
1529 | 3x |
if (discrete) { |
1530 | 1x |
scale_discrete(aesthetics, "nuuk", reverse = reverse, ...) |
1531 |
} else { |
|
1532 | 2x |
scale_continuous(aesthetics, "nuuk", guide = "edge_colourbar", |
1533 | 2x |
reverse = reverse, range = range, ...) |
1534 |
} |
|
1535 |
} |
|
1536 | ||
1537 |
## oslo ------------------------------------------------------------------------ |
|
1538 |
#' Fabio Crameri's *oslo* Sequential Color Scheme |
|
1539 |
#' |
|
1540 |
#' @inheritParams scale_crameri_batlow |
|
1541 |
#' @inheritSection crameri Sequential Color Schemes |
|
1542 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1543 |
#' @references |
|
1544 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1545 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1546 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1547 |
#' |
|
1548 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1549 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1550 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1551 |
#' @source |
|
1552 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1553 |
#' \doi{10.5281/zenodo.4491293} |
|
1554 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1555 |
#' @author N. Frerebeau |
|
1556 |
#' @family sequential color schemes |
|
1557 |
#' @family Fabio Crameri's color schemes |
|
1558 |
#' @name scale_crameri_oslo |
|
1559 |
#' @rdname scale_crameri_oslo |
|
1560 |
NULL |
|
1561 | ||
1562 |
#' @export |
|
1563 |
#' @rdname scale_crameri_oslo |
|
1564 |
scale_colour_oslo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1565 |
discrete = FALSE, aesthetics = "colour") { |
|
1566 | 5x |
if (discrete) { |
1567 | 1x |
scale_discrete(aesthetics, "oslo", reverse = reverse, ...) |
1568 |
} else { |
|
1569 | 4x |
scale_continuous(aesthetics, "oslo", reverse = reverse, |
1570 | 4x |
range = range, ...) |
1571 |
} |
|
1572 |
} |
|
1573 | ||
1574 |
#' @export |
|
1575 |
#' @rdname scale_crameri_oslo |
|
1576 |
scale_color_oslo <- scale_colour_oslo |
|
1577 | ||
1578 |
#' @export |
|
1579 |
#' @rdname scale_crameri_oslo |
|
1580 |
scale_fill_oslo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1581 |
discrete = FALSE, aesthetics = "fill") { |
|
1582 | 3x |
if (discrete) { |
1583 | 1x |
scale_discrete(aesthetics, "oslo", reverse = reverse, ...) |
1584 |
} else { |
|
1585 | 2x |
scale_continuous(aesthetics, "oslo", reverse = reverse, |
1586 | 2x |
range = range, ...) |
1587 |
} |
|
1588 |
} |
|
1589 | ||
1590 |
#' @export |
|
1591 |
#' @rdname scale_crameri_oslo |
|
1592 |
scale_edge_colour_oslo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1593 |
discrete = FALSE, |
|
1594 |
aesthetics = "edge_colour") { |
|
1595 | 5x |
if (discrete) { |
1596 | 1x |
scale_discrete(aesthetics, "oslo", reverse = reverse, ...) |
1597 |
} else { |
|
1598 | 4x |
scale_continuous(aesthetics, "oslo", guide = "edge_colourbar", |
1599 | 4x |
reverse = reverse, range = range, ...) |
1600 |
} |
|
1601 |
} |
|
1602 | ||
1603 |
#' @export |
|
1604 |
#' @rdname scale_crameri_oslo |
|
1605 |
scale_edge_color_oslo <- scale_edge_colour_oslo |
|
1606 | ||
1607 |
#' @export |
|
1608 |
#' @rdname scale_crameri_oslo |
|
1609 |
scale_edge_fill_oslo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1610 |
discrete = FALSE, |
|
1611 |
aesthetics = "edge_fill") { |
|
1612 | 3x |
if (discrete) { |
1613 | 1x |
scale_discrete(aesthetics, "oslo", reverse = reverse, ...) |
1614 |
} else { |
|
1615 | 2x |
scale_continuous(aesthetics, "oslo", guide = "edge_colourbar", |
1616 | 2x |
reverse = reverse, range = range, ...) |
1617 |
} |
|
1618 |
} |
|
1619 | ||
1620 |
## grayC ----------------------------------------------------------------------- |
|
1621 |
#' Fabio Crameri's *grayC* Sequential Color Scheme |
|
1622 |
#' |
|
1623 |
#' @inheritParams scale_crameri_batlow |
|
1624 |
#' @inheritSection crameri Sequential Color Schemes |
|
1625 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1626 |
#' @references |
|
1627 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1628 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1629 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1630 |
#' |
|
1631 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1632 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1633 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1634 |
#' @source |
|
1635 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1636 |
#' \doi{10.5281/zenodo.4491293} |
|
1637 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1638 |
#' @author N. Frerebeau |
|
1639 |
#' @family sequential color schemes |
|
1640 |
#' @family Fabio Crameri's color schemes |
|
1641 |
#' @name scale_crameri_grayC |
|
1642 |
#' @rdname scale_crameri_grayC |
|
1643 |
NULL |
|
1644 | ||
1645 |
#' @export |
|
1646 |
#' @rdname scale_crameri_grayC |
|
1647 |
scale_colour_grayC <- function(..., reverse = FALSE, range = c(0, 1), |
|
1648 |
discrete = FALSE, aesthetics = "colour") { |
|
1649 | 5x |
if (discrete) { |
1650 | 1x |
scale_discrete(aesthetics, "grayC", reverse = reverse, ...) |
1651 |
} else { |
|
1652 | 4x |
scale_continuous(aesthetics, "grayC", reverse = reverse, |
1653 | 4x |
range = range, ...) |
1654 |
} |
|
1655 |
} |
|
1656 | ||
1657 |
#' @export |
|
1658 |
#' @rdname scale_crameri_grayC |
|
1659 |
scale_color_grayC <- scale_colour_grayC |
|
1660 | ||
1661 |
#' @export |
|
1662 |
#' @rdname scale_crameri_grayC |
|
1663 |
scale_fill_grayC <- function(..., reverse = FALSE, range = c(0, 1), |
|
1664 |
discrete = FALSE, aesthetics = "fill") { |
|
1665 | 3x |
if (discrete) { |
1666 | 1x |
scale_discrete(aesthetics, "grayC", reverse = reverse, ...) |
1667 |
} else { |
|
1668 | 2x |
scale_continuous(aesthetics, "grayC", reverse = reverse, |
1669 | 2x |
range = range, ...) |
1670 |
} |
|
1671 |
} |
|
1672 | ||
1673 |
#' @export |
|
1674 |
#' @rdname scale_crameri_grayC |
|
1675 |
scale_edge_colour_grayC <- function(..., reverse = FALSE, range = c(0, 1), |
|
1676 |
discrete = FALSE, |
|
1677 |
aesthetics = "edge_colour") { |
|
1678 | 5x |
if (discrete) { |
1679 | 1x |
scale_discrete(aesthetics, "grayC", reverse = reverse, ...) |
1680 |
} else { |
|
1681 | 4x |
scale_continuous(aesthetics, "grayC", guide = "edge_colourbar", |
1682 | 4x |
reverse = reverse, range = range, ...) |
1683 |
} |
|
1684 |
} |
|
1685 | ||
1686 |
#' @export |
|
1687 |
#' @rdname scale_crameri_grayC |
|
1688 |
scale_edge_color_grayC <- scale_edge_colour_grayC |
|
1689 | ||
1690 |
#' @export |
|
1691 |
#' @rdname scale_crameri_grayC |
|
1692 |
scale_edge_fill_grayC <- function(..., reverse = FALSE, range = c(0, 1), |
|
1693 |
discrete = FALSE, |
|
1694 |
aesthetics = "edge_fill") { |
|
1695 | 3x |
if (discrete) { |
1696 | 1x |
scale_discrete(aesthetics, "grayC", reverse = reverse, ...) |
1697 |
} else { |
|
1698 | 2x |
scale_continuous(aesthetics, "grayC", guide = "edge_colourbar", |
1699 | 2x |
reverse = reverse, range = range, ...) |
1700 |
} |
|
1701 |
} |
|
1702 | ||
1703 |
## hawaii ---------------------------------------------------------------------- |
|
1704 |
#' Fabio Crameri's *hawaii* Sequential Color Scheme |
|
1705 |
#' |
|
1706 |
#' @inheritParams scale_crameri_batlow |
|
1707 |
#' @inheritSection crameri Sequential Color Schemes |
|
1708 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1709 |
#' @references |
|
1710 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1711 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1712 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1713 |
#' |
|
1714 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1715 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1716 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1717 |
#' @source |
|
1718 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1719 |
#' \doi{10.5281/zenodo.4491293} |
|
1720 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1721 |
#' @author N. Frerebeau |
|
1722 |
#' @family sequential color schemes |
|
1723 |
#' @family Fabio Crameri's color schemes |
|
1724 |
#' @name scale_crameri_hawaii |
|
1725 |
#' @rdname scale_crameri_hawaii |
|
1726 |
NULL |
|
1727 | ||
1728 |
#' @export |
|
1729 |
#' @rdname scale_crameri_hawaii |
|
1730 |
scale_colour_hawaii <- function(..., reverse = FALSE, range = c(0, 1), |
|
1731 |
discrete = FALSE, aesthetics = "colour") { |
|
1732 | 5x |
if (discrete) { |
1733 | 1x |
scale_discrete(aesthetics, "hawaii", reverse = reverse, ...) |
1734 |
} else { |
|
1735 | 4x |
scale_continuous(aesthetics, "hawaii", reverse = reverse, |
1736 | 4x |
range = range, ...) |
1737 |
} |
|
1738 |
} |
|
1739 | ||
1740 |
#' @export |
|
1741 |
#' @rdname scale_crameri_hawaii |
|
1742 |
scale_color_hawaii <- scale_colour_hawaii |
|
1743 | ||
1744 |
#' @export |
|
1745 |
#' @rdname scale_crameri_hawaii |
|
1746 |
scale_fill_hawaii <- function(..., reverse = FALSE, range = c(0, 1), |
|
1747 |
discrete = FALSE, aesthetics = "fill") { |
|
1748 | 3x |
if (discrete) { |
1749 | 1x |
scale_discrete(aesthetics, "hawaii", reverse = reverse, ...) |
1750 |
} else { |
|
1751 | 2x |
scale_continuous(aesthetics, "hawaii", reverse = reverse, |
1752 | 2x |
range = range, ...) |
1753 |
} |
|
1754 |
} |
|
1755 | ||
1756 |
#' @export |
|
1757 |
#' @rdname scale_crameri_hawaii |
|
1758 |
scale_edge_colour_hawaii <- function(..., reverse = FALSE, range = c(0, 1), |
|
1759 |
discrete = FALSE, |
|
1760 |
aesthetics = "edge_colour") { |
|
1761 | 5x |
if (discrete) { |
1762 | 1x |
scale_discrete(aesthetics, "hawaii", reverse = reverse, ...) |
1763 |
} else { |
|
1764 | 4x |
scale_continuous(aesthetics, "hawaii", guide = "edge_colourbar", |
1765 | 4x |
reverse = reverse, range = range, ...) |
1766 |
} |
|
1767 |
} |
|
1768 | ||
1769 |
#' @export |
|
1770 |
#' @rdname scale_crameri_hawaii |
|
1771 |
scale_edge_color_hawaii <- scale_edge_colour_hawaii |
|
1772 | ||
1773 |
#' @export |
|
1774 |
#' @rdname scale_crameri_hawaii |
|
1775 |
scale_edge_fill_hawaii <- function(..., reverse = FALSE, range = c(0, 1), |
|
1776 |
discrete = FALSE, |
|
1777 |
aesthetics = "edge_fill") { |
|
1778 | 3x |
if (discrete) { |
1779 | 1x |
scale_discrete(aesthetics, "hawaii", reverse = reverse, ...) |
1780 |
} else { |
|
1781 | 2x |
scale_continuous(aesthetics, "hawaii", guide = "edge_colourbar", |
1782 | 2x |
reverse = reverse, range = range, ...) |
1783 |
} |
|
1784 |
} |
|
1785 | ||
1786 |
## lapaz ----------------------------------------------------------------------- |
|
1787 |
#' Fabio Crameri's *lapaz* Sequential Color Scheme |
|
1788 |
#' |
|
1789 |
#' @inheritParams scale_crameri_batlow |
|
1790 |
#' @inheritSection crameri Sequential Color Schemes |
|
1791 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1792 |
#' @references |
|
1793 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1794 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1795 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1796 |
#' |
|
1797 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1798 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1799 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1800 |
#' @source |
|
1801 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1802 |
#' \doi{10.5281/zenodo.4491293} |
|
1803 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1804 |
#' @author N. Frerebeau |
|
1805 |
#' @family sequential color schemes |
|
1806 |
#' @family Fabio Crameri's color schemes |
|
1807 |
#' @name scale_crameri_lapaz |
|
1808 |
#' @rdname scale_crameri_lapaz |
|
1809 |
NULL |
|
1810 | ||
1811 |
#' @export |
|
1812 |
#' @rdname scale_crameri_lapaz |
|
1813 |
scale_colour_lapaz <- function(..., reverse = FALSE, range = c(0, 1), |
|
1814 |
discrete = FALSE, aesthetics = "colour") { |
|
1815 | 5x |
if (discrete) { |
1816 | 1x |
scale_discrete(aesthetics, "lapaz", reverse = reverse, ...) |
1817 |
} else { |
|
1818 | 4x |
scale_continuous(aesthetics, "lapaz", reverse = reverse, |
1819 | 4x |
range = range, ...) |
1820 |
} |
|
1821 |
} |
|
1822 | ||
1823 |
#' @export |
|
1824 |
#' @rdname scale_crameri_lapaz |
|
1825 |
scale_color_lapaz <- scale_colour_lapaz |
|
1826 | ||
1827 |
#' @export |
|
1828 |
#' @rdname scale_crameri_lapaz |
|
1829 |
scale_fill_lapaz <- function(..., reverse = FALSE, range = c(0, 1), |
|
1830 |
discrete = FALSE, aesthetics = "fill") { |
|
1831 | 3x |
if (discrete) { |
1832 | 1x |
scale_discrete(aesthetics, "lapaz", reverse = reverse, ...) |
1833 |
} else { |
|
1834 | 2x |
scale_continuous(aesthetics, "lapaz", reverse = reverse, |
1835 | 2x |
range = range, ...) |
1836 |
} |
|
1837 |
} |
|
1838 | ||
1839 |
#' @export |
|
1840 |
#' @rdname scale_crameri_lapaz |
|
1841 |
scale_edge_colour_lapaz <- function(..., reverse = FALSE, range = c(0, 1), |
|
1842 |
discrete = FALSE, |
|
1843 |
aesthetics = "edge_colour") { |
|
1844 | 5x |
if (discrete) { |
1845 | 1x |
scale_discrete(aesthetics, "lapaz", reverse = reverse, ...) |
1846 |
} else { |
|
1847 | 4x |
scale_continuous(aesthetics, "lapaz", guide = "edge_colourbar", |
1848 | 4x |
reverse = reverse, range = range, ...) |
1849 |
} |
|
1850 |
} |
|
1851 | ||
1852 |
#' @export |
|
1853 |
#' @rdname scale_crameri_lapaz |
|
1854 |
scale_edge_color_lapaz <- scale_edge_colour_lapaz |
|
1855 | ||
1856 |
#' @export |
|
1857 |
#' @rdname scale_crameri_lapaz |
|
1858 |
scale_edge_fill_lapaz <- function(..., reverse = FALSE, range = c(0, 1), |
|
1859 |
discrete = FALSE, |
|
1860 |
aesthetics = "edge_fill") { |
|
1861 | 3x |
if (discrete) { |
1862 | 1x |
scale_discrete(aesthetics, "lapaz", reverse = reverse, ...) |
1863 |
} else { |
|
1864 | 2x |
scale_continuous(aesthetics, "lapaz", guide = "edge_colourbar", |
1865 | 2x |
reverse = reverse, range = range, ...) |
1866 |
} |
|
1867 |
} |
|
1868 | ||
1869 |
## tokyo ----------------------------------------------------------------------- |
|
1870 |
#' Fabio Crameri's *tokyo* Sequential Color Scheme |
|
1871 |
#' |
|
1872 |
#' @inheritParams scale_crameri_batlow |
|
1873 |
#' @inheritSection crameri Sequential Color Schemes |
|
1874 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1875 |
#' @references |
|
1876 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1877 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1878 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1879 |
#' |
|
1880 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1881 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1882 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1883 |
#' @source |
|
1884 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1885 |
#' \doi{10.5281/zenodo.4491293} |
|
1886 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1887 |
#' @author N. Frerebeau |
|
1888 |
#' @family sequential color schemes |
|
1889 |
#' @family Fabio Crameri's color schemes |
|
1890 |
#' @name scale_crameri_tokyo |
|
1891 |
#' @rdname scale_crameri_tokyo |
|
1892 |
NULL |
|
1893 | ||
1894 |
#' @export |
|
1895 |
#' @rdname scale_crameri_tokyo |
|
1896 |
scale_colour_tokyo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1897 |
discrete = FALSE, aesthetics = "colour") { |
|
1898 | 5x |
if (discrete) { |
1899 | 1x |
scale_discrete(aesthetics, "tokyo", reverse = reverse, ...) |
1900 |
} else { |
|
1901 | 4x |
scale_continuous(aesthetics, "tokyo", reverse = reverse, |
1902 | 4x |
range = range, ...) |
1903 |
} |
|
1904 |
} |
|
1905 | ||
1906 |
#' @export |
|
1907 |
#' @rdname scale_crameri_tokyo |
|
1908 |
scale_color_tokyo <- scale_colour_tokyo |
|
1909 | ||
1910 |
#' @export |
|
1911 |
#' @rdname scale_crameri_tokyo |
|
1912 |
scale_fill_tokyo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1913 |
discrete = FALSE, aesthetics = "fill") { |
|
1914 | 3x |
if (discrete) { |
1915 | 1x |
scale_discrete(aesthetics, "tokyo", reverse = reverse, ...) |
1916 |
} else { |
|
1917 | 2x |
scale_continuous(aesthetics, "tokyo", reverse = reverse, |
1918 | 2x |
range = range, ...) |
1919 |
} |
|
1920 |
} |
|
1921 | ||
1922 |
#' @export |
|
1923 |
#' @rdname scale_crameri_tokyo |
|
1924 |
scale_edge_colour_tokyo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1925 |
discrete = FALSE, |
|
1926 |
aesthetics = "edge_colour") { |
|
1927 | 5x |
if (discrete) { |
1928 | 1x |
scale_discrete(aesthetics, "tokyo", reverse = reverse, ...) |
1929 |
} else { |
|
1930 | 4x |
scale_continuous(aesthetics, "tokyo", guide = "edge_colourbar", |
1931 | 4x |
reverse = reverse, range = range, ...) |
1932 |
} |
|
1933 |
} |
|
1934 | ||
1935 |
#' @export |
|
1936 |
#' @rdname scale_crameri_tokyo |
|
1937 |
scale_edge_color_tokyo <- scale_edge_colour_tokyo |
|
1938 | ||
1939 |
#' @export |
|
1940 |
#' @rdname scale_crameri_tokyo |
|
1941 |
scale_edge_fill_tokyo <- function(..., reverse = FALSE, range = c(0, 1), |
|
1942 |
discrete = FALSE, |
|
1943 |
aesthetics = "edge_fill") { |
|
1944 | 3x |
if (discrete) { |
1945 | 1x |
scale_discrete(aesthetics, "tokyo", reverse = reverse, ...) |
1946 |
} else { |
|
1947 | 2x |
scale_continuous(aesthetics, "tokyo", guide = "edge_colourbar", |
1948 | 2x |
reverse = reverse, range = range, ...) |
1949 |
} |
|
1950 |
} |
|
1951 | ||
1952 |
## buda ------------------------------------------------------------------------ |
|
1953 |
#' Fabio Crameri's *buda* Sequential Color Scheme |
|
1954 |
#' |
|
1955 |
#' @inheritParams scale_crameri_batlow |
|
1956 |
#' @inheritSection crameri Sequential Color Schemes |
|
1957 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1958 |
#' @references |
|
1959 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
1960 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
1961 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
1962 |
#' |
|
1963 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
1964 |
#' science communication. *Nature Communications*, 11, 5444. |
|
1965 |
#' \doi{10.1038/s41467-020-19160-7} |
|
1966 |
#' @source |
|
1967 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
1968 |
#' \doi{10.5281/zenodo.4491293} |
|
1969 |
#' @example inst/examples/ex-crameri-sequential.R |
|
1970 |
#' @author N. Frerebeau |
|
1971 |
#' @family sequential color schemes |
|
1972 |
#' @family Fabio Crameri's color schemes |
|
1973 |
#' @name scale_crameri_buda |
|
1974 |
#' @rdname scale_crameri_buda |
|
1975 |
NULL |
|
1976 | ||
1977 |
#' @export |
|
1978 |
#' @rdname scale_crameri_buda |
|
1979 |
scale_colour_buda <- function(..., reverse = FALSE, range = c(0, 1), |
|
1980 |
discrete = FALSE, aesthetics = "colour") { |
|
1981 | 5x |
if (discrete) { |
1982 | 1x |
scale_discrete(aesthetics, "buda", reverse = reverse, ...) |
1983 |
} else { |
|
1984 | 4x |
scale_continuous(aesthetics, "buda", reverse = reverse, |
1985 | 4x |
range = range, ...) |
1986 |
} |
|
1987 |
} |
|
1988 | ||
1989 |
#' @export |
|
1990 |
#' @rdname scale_crameri_buda |
|
1991 |
scale_color_buda <- scale_colour_buda |
|
1992 | ||
1993 |
#' @export |
|
1994 |
#' @rdname scale_crameri_buda |
|
1995 |
scale_fill_buda <- function(..., reverse = FALSE, range = c(0, 1), |
|
1996 |
discrete = FALSE, aesthetics = "fill") { |
|
1997 | 3x |
if (discrete) { |
1998 | 1x |
scale_discrete(aesthetics, "buda", reverse = reverse, ...) |
1999 |
} else { |
|
2000 | 2x |
scale_continuous(aesthetics, "buda", reverse = reverse, |
2001 | 2x |
range = range, ...) |
2002 |
} |
|
2003 |
} |
|
2004 | ||
2005 |
#' @export |
|
2006 |
#' @rdname scale_crameri_buda |
|
2007 |
scale_edge_colour_buda <- function(..., reverse = FALSE, range = c(0, 1), |
|
2008 |
discrete = FALSE, |
|
2009 |
aesthetics = "edge_colour") { |
|
2010 | 5x |
if (discrete) { |
2011 | 1x |
scale_discrete(aesthetics, "buda", reverse = reverse, ...) |
2012 |
} else { |
|
2013 | 4x |
scale_continuous(aesthetics, "buda", guide = "edge_colourbar", |
2014 | 4x |
reverse = reverse, range = range, ...) |
2015 |
} |
|
2016 |
} |
|
2017 | ||
2018 |
#' @export |
|
2019 |
#' @rdname scale_crameri_buda |
|
2020 |
scale_edge_color_buda <- scale_edge_colour_buda |
|
2021 | ||
2022 |
#' @export |
|
2023 |
#' @rdname scale_crameri_buda |
|
2024 |
scale_edge_fill_buda <- function(..., reverse = FALSE, range = c(0, 1), |
|
2025 |
discrete = FALSE, |
|
2026 |
aesthetics = "edge_fill") { |
|
2027 | 3x |
if (discrete) { |
2028 | 1x |
scale_discrete(aesthetics, "buda", reverse = reverse, ...) |
2029 |
} else { |
|
2030 | 2x |
scale_continuous(aesthetics, "buda", guide = "edge_colourbar", |
2031 | 2x |
reverse = reverse, range = range, ...) |
2032 |
} |
|
2033 |
} |
|
2034 | ||
2035 |
## acton ----------------------------------------------------------------------- |
|
2036 |
#' Fabio Crameri's *acton* Sequential Color Scheme |
|
2037 |
#' |
|
2038 |
#' @inheritParams scale_crameri_batlow |
|
2039 |
#' @inheritSection crameri Sequential Color Schemes |
|
2040 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2041 |
#' @references |
|
2042 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2043 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2044 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2045 |
#' |
|
2046 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2047 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2048 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2049 |
#' @source |
|
2050 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2051 |
#' \doi{10.5281/zenodo.4491293} |
|
2052 |
#' @example inst/examples/ex-crameri-sequential.R |
|
2053 |
#' @author N. Frerebeau |
|
2054 |
#' @family sequential color schemes |
|
2055 |
#' @family Fabio Crameri's color schemes |
|
2056 |
#' @name scale_crameri_acton |
|
2057 |
#' @rdname scale_crameri_acton |
|
2058 |
NULL |
|
2059 | ||
2060 |
#' @export |
|
2061 |
#' @rdname scale_crameri_acton |
|
2062 |
scale_colour_acton <- function(..., reverse = FALSE, range = c(0, 1), |
|
2063 |
discrete = FALSE, aesthetics = "colour") { |
|
2064 | 5x |
if (discrete) { |
2065 | 1x |
scale_discrete(aesthetics, "acton", reverse = reverse, ...) |
2066 |
} else { |
|
2067 | 4x |
scale_continuous(aesthetics, "acton", reverse = reverse, |
2068 | 4x |
range = range, ...) |
2069 |
} |
|
2070 |
} |
|
2071 | ||
2072 |
#' @export |
|
2073 |
#' @rdname scale_crameri_acton |
|
2074 |
scale_color_acton <- scale_colour_acton |
|
2075 | ||
2076 |
#' @export |
|
2077 |
#' @rdname scale_crameri_acton |
|
2078 |
scale_fill_acton <- function(..., reverse = FALSE, range = c(0, 1), |
|
2079 |
discrete = FALSE, aesthetics = "fill") { |
|
2080 | 3x |
if (discrete) { |
2081 | 1x |
scale_discrete(aesthetics, "acton", reverse = reverse, ...) |
2082 |
} else { |
|
2083 | 2x |
scale_continuous(aesthetics, "acton", reverse = reverse, |
2084 | 2x |
range = range, ...) |
2085 |
} |
|
2086 |
} |
|
2087 | ||
2088 |
#' @export |
|
2089 |
#' @rdname scale_crameri_acton |
|
2090 |
scale_edge_colour_acton <- function(..., reverse = FALSE, range = c(0, 1), |
|
2091 |
discrete = FALSE, |
|
2092 |
aesthetics = "edge_colour") { |
|
2093 | 5x |
if (discrete) { |
2094 | 1x |
scale_discrete(aesthetics, "acton", reverse = reverse, ...) |
2095 |
} else { |
|
2096 | 4x |
scale_continuous(aesthetics, "acton", guide = "edge_colourbar", |
2097 | 4x |
reverse = reverse, range = range, ...) |
2098 |
} |
|
2099 |
} |
|
2100 | ||
2101 |
#' @export |
|
2102 |
#' @rdname scale_crameri_acton |
|
2103 |
scale_edge_color_acton <- scale_edge_colour_acton |
|
2104 | ||
2105 |
#' @export |
|
2106 |
#' @rdname scale_crameri_acton |
|
2107 |
scale_edge_fill_acton <- function(..., reverse = FALSE, range = c(0, 1), |
|
2108 |
discrete = FALSE, |
|
2109 |
aesthetics = "edge_fill") { |
|
2110 | 3x |
if (discrete) { |
2111 | 1x |
scale_discrete(aesthetics, "acton", reverse = reverse, ...) |
2112 |
} else { |
|
2113 | 2x |
scale_continuous(aesthetics, "acton", guide = "edge_colourbar", |
2114 | 2x |
reverse = reverse, range = range, ...) |
2115 |
} |
|
2116 |
} |
|
2117 | ||
2118 |
## turku ----------------------------------------------------------------------- |
|
2119 |
#' Fabio Crameri's *turku* Sequential Color Scheme |
|
2120 |
#' |
|
2121 |
#' @inheritParams scale_crameri_batlow |
|
2122 |
#' @inheritSection crameri Sequential Color Schemes |
|
2123 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2124 |
#' @references |
|
2125 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2126 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2127 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2128 |
#' |
|
2129 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2130 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2131 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2132 |
#' @source |
|
2133 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2134 |
#' \doi{10.5281/zenodo.4491293} |
|
2135 |
#' @example inst/examples/ex-crameri-sequential.R |
|
2136 |
#' @author N. Frerebeau |
|
2137 |
#' @family sequential color schemes |
|
2138 |
#' @family Fabio Crameri's color schemes |
|
2139 |
#' @name scale_crameri_turku |
|
2140 |
#' @rdname scale_crameri_turku |
|
2141 |
NULL |
|
2142 | ||
2143 |
#' @export |
|
2144 |
#' @rdname scale_crameri_turku |
|
2145 |
scale_colour_turku <- function(..., reverse = FALSE, range = c(0, 1), |
|
2146 |
discrete = FALSE, aesthetics = "colour") { |
|
2147 | 5x |
if (discrete) { |
2148 | 1x |
scale_discrete(aesthetics, "turku", reverse = reverse, ...) |
2149 |
} else { |
|
2150 | 4x |
scale_continuous(aesthetics, "turku", reverse = reverse, |
2151 | 4x |
range = range, ...) |
2152 |
} |
|
2153 |
} |
|
2154 | ||
2155 |
#' @export |
|
2156 |
#' @rdname scale_crameri_turku |
|
2157 |
scale_color_turku <- scale_colour_turku |
|
2158 | ||
2159 |
#' @export |
|
2160 |
#' @rdname scale_crameri_turku |
|
2161 |
scale_fill_turku <- function(..., reverse = FALSE, range = c(0, 1), |
|
2162 |
discrete = FALSE, aesthetics = "fill") { |
|
2163 | 3x |
if (discrete) { |
2164 | 1x |
scale_discrete(aesthetics, "turku", reverse = reverse, ...) |
2165 |
} else { |
|
2166 | 2x |
scale_continuous(aesthetics, "turku", reverse = reverse, |
2167 | 2x |
range = range, ...) |
2168 |
} |
|
2169 |
} |
|
2170 | ||
2171 |
#' @export |
|
2172 |
#' @rdname scale_crameri_turku |
|
2173 |
scale_edge_colour_turku <- function(..., reverse = FALSE, range = c(0, 1), |
|
2174 |
discrete = FALSE, |
|
2175 |
aesthetics = "edge_colour") { |
|
2176 | 5x |
if (discrete) { |
2177 | 1x |
scale_discrete(aesthetics, "turku", reverse = reverse, ...) |
2178 |
} else { |
|
2179 | 4x |
scale_continuous(aesthetics, "turku", guide = "edge_colourbar", |
2180 | 4x |
reverse = reverse, range = range, ...) |
2181 |
} |
|
2182 |
} |
|
2183 | ||
2184 |
#' @export |
|
2185 |
#' @rdname scale_crameri_turku |
|
2186 |
scale_edge_color_turku <- scale_edge_colour_turku |
|
2187 | ||
2188 |
#' @export |
|
2189 |
#' @rdname scale_crameri_turku |
|
2190 |
scale_edge_fill_turku <- function(..., reverse = FALSE, range = c(0, 1), |
|
2191 |
discrete = FALSE, |
|
2192 |
aesthetics = "edge_fill") { |
|
2193 | 3x |
if (discrete) { |
2194 | 1x |
scale_discrete(aesthetics, "turku", reverse = reverse, ...) |
2195 |
} else { |
|
2196 | 2x |
scale_continuous(aesthetics, "turku", guide = "edge_colourbar", |
2197 | 2x |
reverse = reverse, range = range, ...) |
2198 |
} |
|
2199 |
} |
|
2200 | ||
2201 |
## imola ----------------------------------------------------------------------- |
|
2202 |
#' Fabio Crameri's *imola* Sequential Color Scheme |
|
2203 |
#' |
|
2204 |
#' @inheritParams scale_crameri_batlow |
|
2205 |
#' @inheritSection crameri Sequential Color Schemes |
|
2206 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2207 |
#' @references |
|
2208 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2209 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2210 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2211 |
#' |
|
2212 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2213 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2214 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2215 |
#' @source |
|
2216 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2217 |
#' \doi{10.5281/zenodo.4491293} |
|
2218 |
#' @example inst/examples/ex-crameri-sequential.R |
|
2219 |
#' @author N. Frerebeau |
|
2220 |
#' @family sequential color schemes |
|
2221 |
#' @family Fabio Crameri's color schemes |
|
2222 |
#' @name scale_crameri_imola |
|
2223 |
#' @rdname scale_crameri_imola |
|
2224 |
NULL |
|
2225 | ||
2226 |
#' @export |
|
2227 |
#' @rdname scale_crameri_imola |
|
2228 |
scale_colour_imola <- function(..., reverse = FALSE, range = c(0, 1), |
|
2229 |
discrete = FALSE, aesthetics = "colour") { |
|
2230 | 5x |
if (discrete) { |
2231 | 1x |
scale_discrete(aesthetics, "imola", reverse = reverse, ...) |
2232 |
} else { |
|
2233 | 4x |
scale_continuous(aesthetics, "imola", reverse = reverse, |
2234 | 4x |
range = range, ...) |
2235 |
} |
|
2236 |
} |
|
2237 | ||
2238 |
#' @export |
|
2239 |
#' @rdname scale_crameri_imola |
|
2240 |
scale_color_imola <- scale_colour_imola |
|
2241 | ||
2242 |
#' @export |
|
2243 |
#' @rdname scale_crameri_imola |
|
2244 |
scale_fill_imola <- function(..., reverse = FALSE, range = c(0, 1), |
|
2245 |
discrete = FALSE, aesthetics = "fill") { |
|
2246 | 3x |
if (discrete) { |
2247 | 1x |
scale_discrete(aesthetics, "imola", reverse = reverse, ...) |
2248 |
} else { |
|
2249 | 2x |
scale_continuous(aesthetics, "imola", reverse = reverse, |
2250 | 2x |
range = range, ...) |
2251 |
} |
|
2252 |
} |
|
2253 | ||
2254 |
#' @export |
|
2255 |
#' @rdname scale_crameri_imola |
|
2256 |
scale_edge_colour_imola <- function(..., reverse = FALSE, range = c(0, 1), |
|
2257 |
discrete = FALSE, |
|
2258 |
aesthetics = "edge_colour") { |
|
2259 | 5x |
if (discrete) { |
2260 | 1x |
scale_discrete(aesthetics, "imola", reverse = reverse, ...) |
2261 |
} else { |
|
2262 | 4x |
scale_continuous(aesthetics, "imola", guide = "edge_colourbar", |
2263 | 4x |
reverse = reverse, range = range, ...) |
2264 |
} |
|
2265 |
} |
|
2266 | ||
2267 |
#' @export |
|
2268 |
#' @rdname scale_crameri_imola |
|
2269 |
scale_edge_color_imola <- scale_edge_colour_imola |
|
2270 | ||
2271 |
#' @export |
|
2272 |
#' @rdname scale_crameri_imola |
|
2273 |
scale_edge_fill_imola <- function(..., reverse = FALSE, range = c(0, 1), |
|
2274 |
discrete = FALSE, |
|
2275 |
aesthetics = "edge_fill") { |
|
2276 | 3x |
if (discrete) { |
2277 | 1x |
scale_discrete(aesthetics, "imola", reverse = reverse, ...) |
2278 |
} else { |
|
2279 | 2x |
scale_continuous(aesthetics, "imola", guide = "edge_colourbar", |
2280 | 2x |
reverse = reverse, range = range, ...) |
2281 |
} |
|
2282 |
} |
|
2283 | ||
2284 |
# Multi Sequential ============================================================= |
|
2285 |
## oleron ---------------------------------------------------------------------- |
|
2286 |
#' Fabio Crameri's *oleron* Multi-Sequential Color Scheme |
|
2287 |
#' |
|
2288 |
#' @param ... Arguments passed to [ggplot2::continuous_scale()]. |
|
2289 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
2290 |
#' vector of colors be reversed? |
|
2291 |
#' @param range A length-two [`numeric`] vector specifying the |
|
2292 |
#' fraction of the scheme's color domain to keep. |
|
2293 |
#' @param midpoint A length-one [`numeric`] vector giving the midpoint |
|
2294 |
#' (in data value) of the diverging scale. Defaults to `0`. |
|
2295 |
#' @param aesthetics A [`character`] string or vector of character |
|
2296 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
2297 |
#' @inheritSection crameri Sequential Color Schemes |
|
2298 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2299 |
#' @references |
|
2300 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2301 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2302 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2303 |
#' |
|
2304 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2305 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2306 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2307 |
#' @source |
|
2308 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2309 |
#' \doi{10.5281/zenodo.4491293} |
|
2310 |
#' @example inst/examples/ex-crameri-multisequential.R |
|
2311 |
#' @author N. Frerebeau |
|
2312 |
#' @family multi sequential color schemes |
|
2313 |
#' @family Fabio Crameri's color schemes |
|
2314 |
#' @name scale_crameri_oleron |
|
2315 |
#' @rdname scale_crameri_oleron |
|
2316 |
NULL |
|
2317 | ||
2318 |
#' @export |
|
2319 |
#' @rdname scale_crameri_oleron |
|
2320 |
scale_colour_oleron <- function(..., reverse = FALSE, range = c(0, 1), |
|
2321 |
midpoint = 0, aesthetics = "colour") { |
|
2322 | 6x |
scale_continuous(aesthetics, "oleron", reverse = reverse, range = range, |
2323 | 6x |
midpoint = midpoint, ...) |
2324 |
} |
|
2325 | ||
2326 |
#' @export |
|
2327 |
#' @rdname scale_crameri_oleron |
|
2328 |
scale_color_oleron <- scale_colour_oleron |
|
2329 | ||
2330 |
#' @export |
|
2331 |
#' @rdname scale_crameri_oleron |
|
2332 |
scale_fill_oleron <- function(..., reverse = FALSE, range = c(0, 1), |
|
2333 |
midpoint = 0, aesthetics = "fill") { |
|
2334 | 4x |
scale_continuous(aesthetics, "oleron", reverse = reverse, range = range, |
2335 | 4x |
midpoint = midpoint, ...) |
2336 |
} |
|
2337 | ||
2338 |
## bukavu ---------------------------------------------------------------------- |
|
2339 |
#' Fabio Crameri's *bukavu* Multi-Sequential Color Scheme |
|
2340 |
#' |
|
2341 |
#' @inheritParams scale_crameri_oleron |
|
2342 |
#' @inheritSection crameri Sequential Color Schemes |
|
2343 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2344 |
#' @references |
|
2345 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2346 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2347 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2348 |
#' |
|
2349 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2350 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2351 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2352 |
#' @source |
|
2353 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2354 |
#' \doi{10.5281/zenodo.4491293} |
|
2355 |
#' @example inst/examples/ex-crameri-multisequential.R |
|
2356 |
#' @author N. Frerebeau |
|
2357 |
#' @family multi sequential color schemes |
|
2358 |
#' @family Fabio Crameri's color schemes |
|
2359 |
#' @name scale_crameri_bukavu |
|
2360 |
#' @rdname scale_crameri_bukavu |
|
2361 |
NULL |
|
2362 | ||
2363 |
#' @export |
|
2364 |
#' @rdname scale_crameri_bukavu |
|
2365 |
scale_colour_bukavu <- function(..., reverse = FALSE, range = c(0, 1), |
|
2366 |
midpoint = 0, aesthetics = "colour") { |
|
2367 | 6x |
scale_continuous(aesthetics, "bukavu", reverse = reverse, range = range, |
2368 | 6x |
midpoint = midpoint, ...) |
2369 |
} |
|
2370 | ||
2371 |
#' @export |
|
2372 |
#' @rdname scale_crameri_bukavu |
|
2373 |
scale_color_bukavu <- scale_colour_bukavu |
|
2374 | ||
2375 |
#' @export |
|
2376 |
#' @rdname scale_crameri_bukavu |
|
2377 |
scale_fill_bukavu <- function(..., reverse = FALSE, range = c(0, 1), |
|
2378 |
midpoint = 0, aesthetics = "fill") { |
|
2379 | 4x |
scale_continuous(aesthetics, "bukavu", reverse = reverse, range = range, |
2380 | 4x |
midpoint = midpoint, ...) |
2381 |
} |
|
2382 | ||
2383 |
## fes ------------------------------------------------------------------------- |
|
2384 |
#' Fabio Crameri's *fes* Multi-Sequential Color Scheme |
|
2385 |
#' |
|
2386 |
#' @inheritParams scale_crameri_oleron |
|
2387 |
#' @inheritSection crameri Sequential Color Schemes |
|
2388 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2389 |
#' @references |
|
2390 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2391 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2392 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2393 |
#' |
|
2394 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2395 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2396 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2397 |
#' @source |
|
2398 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2399 |
#' \doi{10.5281/zenodo.4491293} |
|
2400 |
#' @example inst/examples/ex-crameri-multisequential.R |
|
2401 |
#' @author N. Frerebeau |
|
2402 |
#' @family multi sequential color schemes |
|
2403 |
#' @family Fabio Crameri's color schemes |
|
2404 |
#' @name scale_crameri_fes |
|
2405 |
#' @rdname scale_crameri_fes |
|
2406 |
NULL |
|
2407 | ||
2408 |
#' @export |
|
2409 |
#' @rdname scale_crameri_fes |
|
2410 |
scale_colour_fes <- function(..., reverse = FALSE, range = c(0, 1), |
|
2411 |
midpoint = 0, aesthetics = "colour") { |
|
2412 | 6x |
scale_continuous(aesthetics, "fes", reverse = reverse, range = range, |
2413 | 6x |
midpoint = midpoint, ...) |
2414 |
} |
|
2415 | ||
2416 |
#' @export |
|
2417 |
#' @rdname scale_crameri_fes |
|
2418 |
scale_color_fes <- scale_colour_fes |
|
2419 | ||
2420 |
#' @export |
|
2421 |
#' @rdname scale_crameri_fes |
|
2422 |
scale_fill_fes <- function(..., reverse = FALSE, range = c(0, 1), |
|
2423 |
midpoint = 0, aesthetics = "fill") { |
|
2424 | 4x |
scale_continuous(aesthetics, "fes", reverse = reverse, range = range, |
2425 | 4x |
midpoint = midpoint, ...) |
2426 |
} |
|
2427 | ||
2428 |
# Cyclic ======================================================================= |
|
2429 |
## brocO ----------------------------------------------------------------------- |
|
2430 |
#' Fabio Crameri's *brocO* Cyclic Color Scheme |
|
2431 |
#' |
|
2432 |
#' @param ... Arguments passed to [ggplot2::continuous_scale()]. |
|
2433 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
2434 |
#' vector of colors be reversed? |
|
2435 |
#' @param range A length-two [`numeric`] vector specifying the |
|
2436 |
#' fraction of the scheme's color domain to keep. |
|
2437 |
#' @param aesthetics A [`character`] string or vector of character |
|
2438 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
2439 |
#' @param discrete A [`logical`] scalar: should the color scheme be |
|
2440 |
#' used as a discrete scale? |
|
2441 |
#' @inheritSection crameri Diverging Color Schemes |
|
2442 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2443 |
#' @references |
|
2444 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2445 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2446 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2447 |
#' |
|
2448 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2449 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2450 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2451 |
#' @source |
|
2452 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2453 |
#' \doi{10.5281/zenodo.4491293} |
|
2454 |
#' @example inst/examples/ex-crameri-diverging.R |
|
2455 |
#' @author N. Frerebeau |
|
2456 |
#' @family cyclic color schemes |
|
2457 |
#' @family Fabio Crameri's color schemes |
|
2458 |
#' @name scale_crameri_brocO |
|
2459 |
#' @rdname scale_crameri_brocO |
|
2460 |
NULL |
|
2461 | ||
2462 |
#' @export |
|
2463 |
#' @rdname scale_crameri_brocO |
|
2464 |
scale_colour_brocO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2465 |
discrete = FALSE, aesthetics = "colour") { |
|
2466 | 5x |
if (discrete) { |
2467 | 1x |
scale_discrete(aesthetics, "brocO", reverse = reverse, ...) |
2468 |
} else { |
|
2469 | 4x |
scale_continuous(aesthetics, "brocO", reverse = reverse, range = range, ...) |
2470 |
} |
|
2471 |
} |
|
2472 | ||
2473 |
#' @export |
|
2474 |
#' @rdname scale_crameri_brocO |
|
2475 |
scale_color_brocO <- scale_colour_brocO |
|
2476 | ||
2477 |
#' @export |
|
2478 |
#' @rdname scale_crameri_brocO |
|
2479 |
scale_fill_brocO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2480 |
discrete = FALSE, aesthetics = "fill") { |
|
2481 | 3x |
if (discrete) { |
2482 | 1x |
scale_discrete(aesthetics, "brocO", reverse = reverse, ...) |
2483 |
} else { |
|
2484 | 2x |
scale_continuous(aesthetics, "brocO", reverse = reverse, range = range, ...) |
2485 |
} |
|
2486 |
} |
|
2487 | ||
2488 |
## corkO ----------------------------------------------------------------------- |
|
2489 |
#' Fabio Crameri's *corkO* Cyclic Color Scheme |
|
2490 |
#' |
|
2491 |
#' @inheritParams scale_crameri_brocO |
|
2492 |
#' @inheritSection crameri Diverging Color Schemes |
|
2493 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2494 |
#' @references |
|
2495 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2496 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2497 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2498 |
#' |
|
2499 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2500 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2501 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2502 |
#' @source |
|
2503 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2504 |
#' \doi{10.5281/zenodo.4491293} |
|
2505 |
#' @example inst/examples/ex-crameri-diverging.R |
|
2506 |
#' @author N. Frerebeau |
|
2507 |
#' @family cyclic color schemes |
|
2508 |
#' @family Fabio Crameri's color schemes |
|
2509 |
#' @name scale_crameri_corkO |
|
2510 |
#' @rdname scale_crameri_corkO |
|
2511 |
NULL |
|
2512 | ||
2513 |
#' @export |
|
2514 |
#' @rdname scale_crameri_corkO |
|
2515 |
scale_colour_corkO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2516 |
discrete = FALSE, aesthetics = "colour") { |
|
2517 | 5x |
if (discrete) { |
2518 | 1x |
scale_discrete(aesthetics, "corkO", reverse = reverse, ...) |
2519 |
} else { |
|
2520 | 4x |
scale_continuous(aesthetics, "corkO", reverse = reverse, range = range, ...) |
2521 |
} |
|
2522 |
} |
|
2523 | ||
2524 |
#' @export |
|
2525 |
#' @rdname scale_crameri_corkO |
|
2526 |
scale_color_corkO <- scale_colour_corkO |
|
2527 | ||
2528 |
#' @export |
|
2529 |
#' @rdname scale_crameri_corkO |
|
2530 |
scale_fill_corkO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2531 |
discrete = FALSE, aesthetics = "fill") { |
|
2532 | 3x |
if (discrete) { |
2533 | 1x |
scale_discrete(aesthetics, "corkO", reverse = reverse, ...) |
2534 |
} else { |
|
2535 | 2x |
scale_continuous(aesthetics, "corkO", reverse = reverse, range = range, ...) |
2536 |
} |
|
2537 |
} |
|
2538 | ||
2539 |
## vikO ------------------------------------------------------------------------ |
|
2540 |
#' Fabio Crameri's *vikO* Cyclic Color Scheme |
|
2541 |
#' |
|
2542 |
#' @inheritParams scale_crameri_brocO |
|
2543 |
#' @inheritSection crameri Diverging Color Schemes |
|
2544 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2545 |
#' @references |
|
2546 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2547 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2548 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2549 |
#' |
|
2550 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2551 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2552 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2553 |
#' @source |
|
2554 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2555 |
#' \doi{10.5281/zenodo.4491293} |
|
2556 |
#' @example inst/examples/ex-crameri-diverging.R |
|
2557 |
#' @author N. Frerebeau |
|
2558 |
#' @family cyclic color schemes |
|
2559 |
#' @family Fabio Crameri's color schemes |
|
2560 |
#' @name scale_crameri_vikO |
|
2561 |
#' @rdname scale_crameri_vikO |
|
2562 |
NULL |
|
2563 | ||
2564 |
#' @export |
|
2565 |
#' @rdname scale_crameri_vikO |
|
2566 |
scale_colour_vikO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2567 |
discrete = FALSE, aesthetics = "colour") { |
|
2568 | 5x |
if (discrete) { |
2569 | 1x |
scale_discrete(aesthetics, "vikO", reverse = reverse, ...) |
2570 |
} else { |
|
2571 | 4x |
scale_continuous(aesthetics, "vikO", reverse = reverse, range = range, ...) |
2572 |
} |
|
2573 |
} |
|
2574 | ||
2575 |
#' @export |
|
2576 |
#' @rdname scale_crameri_vikO |
|
2577 |
scale_color_vikO <- scale_colour_vikO |
|
2578 | ||
2579 |
#' @export |
|
2580 |
#' @rdname scale_crameri_vikO |
|
2581 |
scale_fill_vikO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2582 |
discrete = FALSE, aesthetics = "fill") { |
|
2583 | 3x |
if (discrete) { |
2584 | 1x |
scale_discrete(aesthetics, "vikO", reverse = reverse, ...) |
2585 |
} else { |
|
2586 | 2x |
scale_continuous(aesthetics, "vikO", reverse = reverse, range = range, ...) |
2587 |
} |
|
2588 |
} |
|
2589 | ||
2590 |
## romaO ----------------------------------------------------------------------- |
|
2591 |
#' Fabio Crameri's *romaO* Cyclic Color Scheme |
|
2592 |
#' |
|
2593 |
#' @inheritParams scale_crameri_brocO |
|
2594 |
#' @inheritSection crameri Diverging Color Schemes |
|
2595 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2596 |
#' @references |
|
2597 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2598 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2599 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2600 |
#' |
|
2601 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2602 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2603 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2604 |
#' @source |
|
2605 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2606 |
#' \doi{10.5281/zenodo.4491293} |
|
2607 |
#' @example inst/examples/ex-crameri-diverging.R |
|
2608 |
#' @author N. Frerebeau |
|
2609 |
#' @family cyclic color schemes |
|
2610 |
#' @family Fabio Crameri's color schemes |
|
2611 |
#' @name scale_crameri_romaO |
|
2612 |
#' @rdname scale_crameri_romaO |
|
2613 |
NULL |
|
2614 | ||
2615 |
#' @export |
|
2616 |
#' @rdname scale_crameri_romaO |
|
2617 |
scale_colour_romaO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2618 |
discrete = FALSE, aesthetics = "colour") { |
|
2619 | 5x |
if (discrete) { |
2620 | 1x |
scale_discrete(aesthetics, "romaO", reverse = reverse, ...) |
2621 |
} else { |
|
2622 | 4x |
scale_continuous(aesthetics, "romaO", reverse = reverse, range = range, ...) |
2623 |
} |
|
2624 |
} |
|
2625 | ||
2626 |
#' @export |
|
2627 |
#' @rdname scale_crameri_romaO |
|
2628 |
scale_color_romaO <- scale_colour_romaO |
|
2629 | ||
2630 |
#' @export |
|
2631 |
#' @rdname scale_crameri_romaO |
|
2632 |
scale_fill_romaO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2633 |
discrete = FALSE, aesthetics = "fill") { |
|
2634 | 3x |
if (discrete) { |
2635 | 1x |
scale_discrete(aesthetics, "romaO", reverse = reverse, ...) |
2636 |
} else { |
|
2637 | 2x |
scale_continuous(aesthetics, "romaO", reverse = reverse, range = range, ...) |
2638 |
} |
|
2639 |
} |
|
2640 | ||
2641 |
## bamO ------------------------------------------------------------------------ |
|
2642 |
#' Fabio Crameri's *bamO* Cyclic Color Scheme |
|
2643 |
#' |
|
2644 |
#' @inheritParams scale_crameri_brocO |
|
2645 |
#' @inheritSection crameri Diverging Color Schemes |
|
2646 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
2647 |
#' @references |
|
2648 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
2649 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
2650 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
2651 |
#' |
|
2652 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
2653 |
#' science communication. *Nature Communications*, 11, 5444. |
|
2654 |
#' \doi{10.1038/s41467-020-19160-7} |
|
2655 |
#' @source |
|
2656 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
2657 |
#' \doi{10.5281/zenodo.4491293} |
|
2658 |
#' @example inst/examples/ex-crameri-diverging.R |
|
2659 |
#' @author N. Frerebeau |
|
2660 |
#' @family cyclic color schemes |
|
2661 |
#' @family Fabio Crameri's color schemes |
|
2662 |
#' @name scale_crameri_bamO |
|
2663 |
#' @rdname scale_crameri_bamO |
|
2664 |
NULL |
|
2665 | ||
2666 |
#' @export |
|
2667 |
#' @rdname scale_crameri_bamO |
|
2668 |
scale_colour_bamO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2669 |
discrete = FALSE, aesthetics = "colour") { |
|
2670 | 5x |
if (discrete) { |
2671 | 1x |
scale_discrete(aesthetics, "bamO", reverse = reverse, ...) |
2672 |
} else { |
|
2673 | 4x |
scale_continuous(aesthetics, "bamO", reverse = reverse, range = range, ...) |
2674 |
} |
|
2675 |
} |
|
2676 | ||
2677 |
#' @export |
|
2678 |
#' @rdname scale_crameri_bamO |
|
2679 |
scale_color_bamO <- scale_colour_bamO |
|
2680 | ||
2681 |
#' @export |
|
2682 |
#' @rdname scale_crameri_bamO |
|
2683 |
scale_fill_bamO <- function(..., reverse = FALSE, range = c(0, 1), |
|
2684 |
discrete = FALSE, aesthetics = "fill") { |
|
2685 | 3x |
if (discrete) { |
2686 | 1x |
scale_discrete(aesthetics, "bamO", reverse = reverse, ...) |
2687 |
} else { |
|
2688 | 2x |
scale_continuous(aesthetics, "bamO", reverse = reverse, range = range, ...) |
2689 |
} |
|
2690 |
} |
1 |
# PALETTES |
|
2 | ||
3 |
# Palettes ===================================================================== |
|
4 |
## Color ----------------------------------------------------------------------- |
|
5 |
#' Color Mapping |
|
6 |
#' |
|
7 |
#' Maps values to colors. |
|
8 |
#' @param scheme A [`character`] string giving the name of the scheme to be |
|
9 |
#' used (see [color()]). |
|
10 |
#' @param domain A [`numeric`] range or a vector of categorical data specifying |
|
11 |
#' the possible values that can be mapped. |
|
12 |
#' @param midpoint A length-one [`numeric`] vector specifying the mid-point of |
|
13 |
#' input range. |
|
14 |
#' @param ordered A [`logical`] scalar: should the levels be treated as already |
|
15 |
#' in the correct order? |
|
16 |
#' @param missing The color to return for `NA` values. |
|
17 |
#' @param ... Further parameters to be passed to [color()]. |
|
18 |
#' @details |
|
19 |
#' A wrapper around `palette_color_continuous()` and |
|
20 |
#' `palette_color_discrete()`. |
|
21 |
#' @return |
|
22 |
#' A palette [`function`] that when called with a single argument returns |
|
23 |
#' a [`character`] vector of colors. |
|
24 |
#' @example inst/examples/ex-palette-color.R |
|
25 |
#' @family palettes |
|
26 |
#' @export |
|
27 |
palette_color_picker <- function(scheme, domain = NULL, midpoint = NULL, |
|
28 |
ordered = FALSE, missing = NULL, ...) { |
|
29 | ||
30 | 6x |
scheme <- color(scheme, ...) |
31 | 6x |
col <- scheme() |
32 | 6x |
miss <- missing %||% attr(scheme, "missing") |
33 | 3x |
if (is.na(miss)) miss <- "#DDDDDD" |
34 | ||
35 | 6x |
quali <- attr(scheme, "type") == "qualitative" |
36 | 6x |
if (quali) { |
37 | 3x |
fun <- palette_color_discrete( |
38 | 3x |
colors = col, |
39 | 3x |
domain = domain, |
40 | 3x |
ordered = ordered, |
41 | 3x |
missing = miss |
42 |
) |
|
43 |
} else { |
|
44 | 3x |
fun <- palette_color_continuous( |
45 | 3x |
colors = col, |
46 | 3x |
domain = domain, |
47 | 3x |
midpoint = midpoint, |
48 | 3x |
missing = miss |
49 |
) |
|
50 |
} |
|
51 | ||
52 | 6x |
fun |
53 |
} |
|
54 | ||
55 |
#' @export |
|
56 |
#' @rdname palette_color_picker |
|
57 |
palette_colour_picker <- palette_color_picker |
|
58 | ||
59 |
#' Color Mapping (continuous) |
|
60 |
#' |
|
61 |
#' Maps continuous values to an interpolated colors gradient. |
|
62 |
#' @param colors A vector of colors or a [`function`] that when called with a |
|
63 |
#' single argument (an integer specifying the number of colors) returns a |
|
64 |
#' vector of colors. If `NULL` (the default), uses *YlOrRd*. |
|
65 |
#' @param domain A [`numeric`] range specifying the possible values that can be |
|
66 |
#' mapped. |
|
67 |
#' @param midpoint A length-one [`numeric`] vector specifying the mid-point of |
|
68 |
#' input range. |
|
69 |
#' @param missing The color to return for `NA` values. |
|
70 |
#' @return |
|
71 |
#' A palette [`function`] that when called with a single argument |
|
72 |
#' (a [`numeric`] vector of continuous values) returns a [`character`] vector |
|
73 |
#' of colors. |
|
74 |
#' @seealso [grDevices::colorRamp()] |
|
75 |
#' @example inst/examples/ex-palette-continuous.R |
|
76 |
#' @family palettes |
|
77 |
#' @export |
|
78 |
palette_color_continuous <- function(colors = NULL, domain = NULL, |
|
79 |
midpoint = NULL, missing = "#DDDDDD") { |
|
80 | ||
81 | 14x |
force(colors) |
82 | 14x |
force(domain) |
83 | 14x |
force(midpoint) |
84 | 14x |
force(missing) |
85 | ||
86 | 14x |
function(x, ...) { |
87 | 14x |
need_continuous(x) |
88 | ||
89 | 12x |
rng <- if (!is.null(domain)) range(domain, finite = TRUE) else range(x, finite = TRUE) |
90 | 12x |
if (!is.null(midpoint) && is.numeric(midpoint)) { |
91 | 1x |
x <- scale_midpoint(x, to = c(0, 1), from = rng, midpoint = midpoint) |
92 |
} else { |
|
93 | 11x |
x <- scale_range(x, to = c(0, 1), from = rng) |
94 |
} |
|
95 | ||
96 | 12x |
out <- x < 0 | x > 1 |
97 | 12x |
if (any(out, na.rm = TRUE)) { |
98 | 2x |
x[out] <- NA |
99 | 2x |
warning(tr_("Some values were outside the color scale."), call. = FALSE) |
100 |
} |
|
101 | ||
102 | 12x |
OK <- !is.na(x) |
103 | 12x |
if (is.null(colors)) { |
104 | 1x |
colors <- color(palette = "YlOrBr")(9) |
105 |
} |
|
106 | 12x |
if (is.function(colors)) { |
107 | 1x |
colors <- colors(9) |
108 |
} |
|
109 | 12x |
colors <- grDevices::colorRamp(colors)(x[OK], ...) |
110 | ||
111 | 12x |
col <- rep(missing, length(x)) |
112 | 12x |
col[OK] <- grDevices::rgb(colors, maxColorValue = 255) |
113 | 12x |
col |
114 |
} |
|
115 |
} |
|
116 | ||
117 |
#' @export |
|
118 |
#' @rdname palette_color_continuous |
|
119 |
palette_colour_continuous <- palette_color_continuous |
|
120 | ||
121 |
#' Color Mapping (discrete) |
|
122 |
#' |
|
123 |
#' Maps categorical values to colors. |
|
124 |
#' @param colors A vector of colors or a [`function`] that when called with a |
|
125 |
#' single argument (an integer specifying the number of colors) returns a |
|
126 |
#' vector of colors. If `NULL` (the default), uses *discrete rainbow*. |
|
127 |
#' @param domain A vector of categorical data specifying the possible values |
|
128 |
#' that can be mapped. |
|
129 |
#' @param ordered A [`logical`] scalar: should the levels be treated as already |
|
130 |
#' in the correct order? |
|
131 |
#' @param missing The color to return for `NA` values. |
|
132 |
#' @return |
|
133 |
#' A palette [`function`] that when called with a single argument |
|
134 |
#' (a vector of categorical values) returns a [`character`] vector of colors. |
|
135 |
#' @example inst/examples/ex-palette-discrete.R |
|
136 |
#' @family palettes |
|
137 |
#' @export |
|
138 |
palette_color_discrete <- function(colors = NULL, domain = NULL, |
|
139 |
ordered = FALSE, missing = "#DDDDDD") { |
|
140 | ||
141 | 15x |
force(colors) |
142 | 15x |
force(domain) |
143 | 15x |
force(ordered) |
144 | 15x |
force(missing) |
145 | ||
146 |
## If named colors, override user settings |
|
147 | 15x |
if (!is.null(names(colors))) { |
148 | 1x |
domain <- names(colors) |
149 | 1x |
ordered <- TRUE |
150 |
} |
|
151 | ||
152 | 15x |
function(x, ...) { |
153 | 15x |
need_discrete(x) |
154 | ||
155 | 15x |
domain <- make_levels(x, levels = domain, ordered = ordered) |
156 | 15x |
n <- length(domain) |
157 | 15x |
x <- match(as.character(x), domain) |
158 | ||
159 | 15x |
OK <- !is.na(x) |
160 | 15x |
if (is.null(colors)) { |
161 | 2x |
colors <- color(palette = "discreterainbow")(n) |
162 |
} |
|
163 | 15x |
if (is.function(colors)) { |
164 | 1x |
colors <- colors(n) |
165 |
} |
|
166 | ||
167 | 15x |
if (length(colors) < n) { |
168 | 3x |
msg <- tr_("Only %d colors were specified (%d are required).") |
169 | 3x |
warning(sprintf(msg, length(colors), n), call. = FALSE) |
170 |
} |
|
171 | 15x |
col <- colors[x] |
172 | 15x |
col[!OK] <- missing |
173 | 15x |
col |
174 |
} |
|
175 |
} |
|
176 | ||
177 |
#' @export |
|
178 |
#' @rdname palette_color_discrete |
|
179 |
palette_colour_discrete <- palette_color_discrete |
|
180 | ||
181 |
## Symbol ---------------------------------------------------------------------- |
|
182 |
#' Symbol Mapping |
|
183 |
#' |
|
184 |
#' @param symbols,types A vector of symbols or line types. |
|
185 |
#' @param domain A vector of categorical data specifying the possible values |
|
186 |
#' that can be mapped. |
|
187 |
#' @param ordered A [`logical`] scalar: should the levels be treated as already |
|
188 |
#' in the correct order? |
|
189 |
#' @param ... Currently not used. |
|
190 |
#' @return |
|
191 |
#' A palette [`function`] that when called with a single argument |
|
192 |
#' (a [`character`] vector of categorical values) returns a vector of symbols. |
|
193 |
#' @example inst/examples/ex-palette-discrete.R |
|
194 |
#' @family palettes |
|
195 |
#' @export |
|
196 |
palette_shape <- function(symbols = NULL, domain = NULL, ordered = FALSE, ...) { |
|
197 | ||
198 | 9x |
force(symbols) |
199 | 9x |
force(domain) |
200 | 9x |
force(ordered) |
201 | ||
202 |
## If named symbol, override user settings |
|
203 | 9x |
if (!is.null(names(symbols))) { |
204 | 1x |
domain <- names(symbols) |
205 | 1x |
ordered <- TRUE |
206 |
} |
|
207 | ||
208 | 9x |
function(x) { |
209 | 9x |
need_discrete(x) |
210 | ||
211 | 9x |
domain <- make_levels(x, levels = domain, ordered = ordered) |
212 | 9x |
x <- match(as.character(x), domain) |
213 | ||
214 | 9x |
if (is.null(symbols)) { |
215 | 4x |
n <- length(domain) |
216 | 4x |
if (n > 6) { |
217 | 1x |
warning(tr_("Consider specifying symbols manually: "), |
218 | 1x |
tr_("more than 6 becomes difficult to discriminate."), |
219 | 1x |
call. = FALSE) |
220 |
} |
|
221 | 4x |
symbols <- c(16, 17, 15, 3, 7, 8)[seq_len(n)] |
222 |
} |
|
223 | 9x |
symbols[x] |
224 |
} |
|
225 |
} |
|
226 | ||
227 |
#' @export |
|
228 |
#' @rdname palette_shape |
|
229 |
palette_line <- function(types = NULL, domain = NULL, ordered = FALSE, ...) { |
|
230 | ! |
if (is.null(types)) { |
231 | ! |
types <- c("solid", "22", "42", "44", "13", "1343", "73", "2262", |
232 | ! |
"12223242", "F282", "F4448444", "224282F2", "F1") |
233 |
} |
|
234 | ! |
palette_shape(symbols = types, domain = domain, ordered = ordered, ...) |
235 |
} |
|
236 | ||
237 |
## Size ------------------------------------------------------------------------ |
|
238 |
#' Symbol Size Mapping |
|
239 |
#' |
|
240 |
#' @param range A length-two [`numeric`] vector giving range of possible sizes |
|
241 |
#' (greater than 0). |
|
242 |
#' @param midpoint A length-one [`numeric`] vector specifying the data mid-point. |
|
243 |
#' @param ... Currently not used. |
|
244 |
#' @return |
|
245 |
#' A palette [`function`] that when called with a single argument |
|
246 |
#' (a [`numeric`] vector of continuous values) returns a [`numeric`] vector |
|
247 |
#' giving the amount by which plotting text and symbols should be magnified |
|
248 |
#' relative to the default. |
|
249 |
#' @example inst/examples/ex-palette-continuous.R |
|
250 |
#' @family palettes |
|
251 |
#' @name palette_size |
|
252 |
#' @rdname palette_size |
|
253 |
NULL |
|
254 | ||
255 |
#' @export |
|
256 |
#' @rdname palette_size |
|
257 |
palette_size_sequential <- function(range = c(1, 6), ...) { |
|
258 | ||
259 | 6x |
force(range) |
260 | ||
261 | 6x |
function(x) { |
262 | 6x |
need_continuous(x) |
263 | 5x |
x <- scale_range(x) |
264 | 5x |
scale_range(sqrt(x), to = range(range, na.rm = TRUE)) |
265 |
} |
|
266 |
} |
|
267 | ||
268 |
#' @export |
|
269 |
#' @rdname palette_size |
|
270 |
palette_size_diverging <- function(range = c(1, 6), midpoint = 0, ...) { |
|
271 | ||
272 | 2x |
force(range) |
273 | 2x |
force(midpoint) |
274 | ||
275 | 2x |
function(x) { |
276 | 2x |
need_continuous(x) |
277 | 1x |
x <- scale_midpoint(abs(x), midpoint = midpoint) |
278 | 1x |
scale_range(sqrt(x), to = range(range, na.rm = TRUE)) |
279 |
} |
|
280 |
} |
|
281 | ||
282 |
# Scales ======================================================================= |
|
283 |
#' Rescale Continuous Vector (minimum, maximum) |
|
284 |
#' |
|
285 |
#' Rescales continuous vector to have specified minimum and maximum. |
|
286 |
#' @param x A [`numeric`] vector. |
|
287 |
#' @param to A length-two [`numeric`] vector specifying the output range. |
|
288 |
#' @param from A length-two [`numeric`] vector specifying the input range. |
|
289 |
#' @return A [`numeric`] vector. |
|
290 |
#' @family scales |
|
291 |
#' @keywords internal |
|
292 |
#' @noRd |
|
293 |
scale_range <- function(x, to = c(0, 1), from = range(x, finite = TRUE)) { |
|
294 | 1x |
if (is_zero(to) || is_zero(from)) return(ifelse(is.na(x), NA, mean(to))) |
295 | 25x |
(x - from[1L]) / diff(from) * diff(to) + to[1L] |
296 |
} |
|
297 | ||
298 |
#' Rescale Continuous Vector (minimum, midpoint, maximum) |
|
299 |
#' |
|
300 |
#' Rescales continuous vector to have specified minimum, midpoint and maximum. |
|
301 |
#' @param x A [`numeric`] vector. |
|
302 |
#' @param to A length-two [`numeric`] vector specifying the output range. |
|
303 |
#' @param from A length-two [`numeric`] vector specifying the input range. |
|
304 |
#' @param midpoint A length-one [`numeric`] vector specifying the mid-point of |
|
305 |
#' input range. |
|
306 |
#' @return A [`numeric`] vector. |
|
307 |
#' @family scales |
|
308 |
#' @keywords internal |
|
309 |
#' @noRd |
|
310 |
scale_midpoint <- function(x, to = c(0, 1), from = range(x, finite = TRUE), |
|
311 |
midpoint = 0) { |
|
312 | ! |
if (is_zero(to) || is_zero(from)) return(ifelse(is.na(x), NA, mean(to))) |
313 | 4x |
extent <- 2 * max(abs(from - midpoint)) |
314 | 4x |
(x - midpoint) / extent * diff(to) + mean(to) |
315 |
} |
|
316 | ||
317 |
# Helpers ====================================================================== |
|
318 |
need_continuous <- function(x) { |
|
319 | 22x |
if (!is.numeric(x)) { |
320 | 4x |
stop(tr_("Discrete value supplied to continuous scale."), call. = FALSE) |
321 |
} |
|
322 | 18x |
invisible(x) |
323 |
} |
|
324 | ||
325 |
need_discrete <- function(x) { |
|
326 | 24x |
if (is.double(x)) { |
327 | 2x |
warning(tr_("Continuous value supplied to discrete scale."), call. = FALSE) |
328 |
} |
|
329 | 24x |
invisible(x) |
330 |
} |
|
331 | ||
332 |
is_zero <- function(x, tolerance = sqrt(.Machine$double.eps)) { |
|
333 | 59x |
diff(range(x)) <= tolerance |
334 |
} |
|
335 | ||
336 |
make_levels <- function(x, levels = NULL, ordered = FALSE) { |
|
337 | 12x |
if (!is.null(levels)) return(make_levels(x = levels, ordered = ordered)) |
338 | ||
339 | ! |
if (is.null(x)) levels <- NULL |
340 | ! |
else if (is.factor(x)) levels <- levels(x) |
341 | 4x |
else if (ordered) levels <- unique(x) |
342 | 20x |
else levels <- sort(unique(x)) |
343 | 24x |
levels |
344 |
} |
1 |
# Paul Tol's color schemes |
|
2 |
#' @include color.R |
|
3 |
NULL |
|
4 | ||
5 |
# Discrete ===================================================================== |
|
6 |
## Bright ---------------------------------------------------------------------- |
|
7 |
#' Paul Tol's *bright* Discrete Color Scheme |
|
8 |
#' |
|
9 |
#' @param ... Arguments passed to [ggplot2::discrete_scale()]. |
|
10 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
11 |
#' vector of colors be reversed? |
|
12 |
#' @param aesthetics A [`character`] string or vector of character |
|
13 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
14 |
#' @inheritSection tol Qualitative Color Schemes |
|
15 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
16 |
#' @references |
|
17 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
18 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
19 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
20 |
#' @example inst/examples/ex-tol-discrete.R |
|
21 |
#' @author N. Frerebeau |
|
22 |
#' @family qualitative color schemes |
|
23 |
#' @family Paul Tol's color schemes |
|
24 |
#' @name scale_tol_bright |
|
25 |
#' @rdname scale_tol_bright |
|
26 |
NULL |
|
27 | ||
28 |
#' @export |
|
29 |
#' @rdname scale_tol_bright |
|
30 |
scale_colour_bright <- function(..., reverse = FALSE, aesthetics = "colour") { |
|
31 | 5x |
scale_discrete(aesthetics, "bright", reverse = reverse, ...) |
32 |
} |
|
33 | ||
34 |
#' @export |
|
35 |
#' @rdname scale_tol_bright |
|
36 |
scale_color_bright <- scale_colour_bright |
|
37 | ||
38 |
#' @export |
|
39 |
#' @rdname scale_tol_bright |
|
40 |
scale_fill_bright <- function(..., reverse = FALSE, aesthetics = "fill") { |
|
41 | 3x |
scale_discrete(aesthetics, "bright", reverse = reverse, ...) |
42 |
} |
|
43 | ||
44 |
#' @export |
|
45 |
#' @rdname scale_tol_bright |
|
46 |
scale_edge_colour_bright <- function(..., reverse = FALSE, |
|
47 |
aesthetics = "edge_colour") { |
|
48 | 5x |
scale_discrete(aesthetics, "bright", reverse = reverse, ...) |
49 |
} |
|
50 | ||
51 |
#' @export |
|
52 |
#' @rdname scale_tol_bright |
|
53 |
scale_edge_color_bright <- scale_edge_colour_bright |
|
54 | ||
55 |
#' @export |
|
56 |
#' @rdname scale_tol_bright |
|
57 |
scale_edge_fill_bright <- function(..., reverse = FALSE, |
|
58 |
aesthetics = "edge_fill") { |
|
59 | 3x |
scale_discrete(aesthetics, "bright", reverse = reverse, ...) |
60 |
} |
|
61 | ||
62 |
## High contrast --------------------------------------------------------------- |
|
63 |
#' Paul Tol's *high contrast* Discrete Color Scheme |
|
64 |
#' |
|
65 |
#' @inheritParams scale_tol_bright |
|
66 |
#' @inheritSection tol Qualitative Color Schemes |
|
67 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
68 |
#' @references |
|
69 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
70 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
71 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
72 |
#' @example inst/examples/ex-tol-discrete.R |
|
73 |
#' @author N. Frerebeau |
|
74 |
#' @family qualitative color schemes |
|
75 |
#' @family Paul Tol's color schemes |
|
76 |
#' @name scale_tol_highcontrast |
|
77 |
#' @rdname scale_tol_highcontrast |
|
78 |
NULL |
|
79 | ||
80 |
#' @export |
|
81 |
#' @rdname scale_tol_highcontrast |
|
82 |
scale_colour_highcontrast <- function(..., reverse = FALSE, |
|
83 |
aesthetics = "colour") { |
|
84 | 5x |
scale_discrete(aesthetics, "highcontrast", reverse = reverse, ...) |
85 |
} |
|
86 | ||
87 |
#' @export |
|
88 |
#' @rdname scale_tol_highcontrast |
|
89 |
scale_color_highcontrast <- scale_colour_highcontrast |
|
90 | ||
91 |
#' @export |
|
92 |
#' @rdname scale_tol_highcontrast |
|
93 |
scale_fill_highcontrast <- function(..., reverse = FALSE, |
|
94 |
aesthetics = "fill") { |
|
95 | 3x |
scale_discrete(aesthetics, "highcontrast", reverse = reverse, ...) |
96 |
} |
|
97 | ||
98 |
#' @export |
|
99 |
#' @rdname scale_tol_highcontrast |
|
100 |
scale_edge_colour_highcontrast <- function(..., reverse = FALSE, |
|
101 |
aesthetics = "edge_colour") { |
|
102 | 5x |
scale_discrete(aesthetics, "highcontrast", reverse = reverse, ...) |
103 |
} |
|
104 | ||
105 |
#' @export |
|
106 |
#' @rdname scale_tol_highcontrast |
|
107 |
scale_edge_color_highcontrast <- scale_edge_colour_highcontrast |
|
108 | ||
109 |
#' @export |
|
110 |
#' @rdname scale_tol_highcontrast |
|
111 |
scale_edge_fill_highcontrast <- function(..., reverse = FALSE, |
|
112 |
aesthetics = "edge_fill") { |
|
113 | 3x |
scale_discrete(aesthetics, "highcontrast", reverse = reverse, ...) |
114 |
} |
|
115 | ||
116 |
## Vibrant --------------------------------------------------------------------- |
|
117 |
#' Paul Tol's *vibrant* Discrete Color Scheme |
|
118 |
#' |
|
119 |
#' @inheritParams scale_tol_bright |
|
120 |
#' @inheritSection tol Qualitative Color Schemes |
|
121 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
122 |
#' @references |
|
123 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
124 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
125 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
126 |
#' @example inst/examples/ex-tol-discrete.R |
|
127 |
#' @author N. Frerebeau |
|
128 |
#' @family qualitative color schemes |
|
129 |
#' @family Paul Tol's color schemes |
|
130 |
#' @name scale_tol_vibrant |
|
131 |
#' @rdname scale_tol_vibrant |
|
132 |
NULL |
|
133 | ||
134 |
#' @export |
|
135 |
#' @rdname scale_tol_vibrant |
|
136 |
scale_colour_vibrant <- function(..., reverse = FALSE, aesthetics = "colour") { |
|
137 | 5x |
scale_discrete(aesthetics, "vibrant", reverse = reverse, ...) |
138 |
} |
|
139 | ||
140 |
#' @export |
|
141 |
#' @rdname scale_tol_vibrant |
|
142 |
scale_color_vibrant <- scale_colour_vibrant |
|
143 | ||
144 |
#' @export |
|
145 |
#' @rdname scale_tol_vibrant |
|
146 |
scale_fill_vibrant <- function(..., reverse = FALSE, aesthetics = "fill") { |
|
147 | 3x |
scale_discrete(aesthetics, "vibrant", reverse = reverse, ...) |
148 |
} |
|
149 | ||
150 |
#' @export |
|
151 |
#' @rdname scale_tol_vibrant |
|
152 |
scale_edge_colour_vibrant <- function(..., reverse = FALSE, |
|
153 |
aesthetics = "edge_colour") { |
|
154 | 5x |
scale_discrete(aesthetics, "vibrant", reverse = reverse, ...) |
155 |
} |
|
156 | ||
157 |
#' @export |
|
158 |
#' @rdname scale_tol_vibrant |
|
159 |
scale_edge_color_vibrant <- scale_edge_colour_vibrant |
|
160 | ||
161 |
#' @export |
|
162 |
#' @rdname scale_tol_vibrant |
|
163 |
scale_edge_fill_vibrant <- function(..., reverse = FALSE, |
|
164 |
aesthetics = "edge_fill") { |
|
165 | 3x |
scale_discrete(aesthetics, "vibrant", reverse = reverse, ...) |
166 |
} |
|
167 | ||
168 |
## Muted ----------------------------------------------------------------------- |
|
169 |
#' Paul Tol's *muted* Discrete Color Scheme |
|
170 |
#' |
|
171 |
#' @inheritParams scale_tol_bright |
|
172 |
#' @inheritSection tol Qualitative Color Schemes |
|
173 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
174 |
#' @references |
|
175 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
176 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
177 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
178 |
#' @example inst/examples/ex-tol-discrete.R |
|
179 |
#' @author N. Frerebeau |
|
180 |
#' @family qualitative color schemes |
|
181 |
#' @family Paul Tol's color schemes |
|
182 |
#' @name scale_tol_muted |
|
183 |
#' @rdname scale_tol_muted |
|
184 |
NULL |
|
185 | ||
186 |
#' @export |
|
187 |
#' @rdname scale_tol_muted |
|
188 |
scale_colour_muted <- function(..., reverse = FALSE, aesthetics = "colour") { |
|
189 | 8x |
scale_discrete(aesthetics, "muted", reverse = reverse, ...) |
190 |
} |
|
191 | ||
192 |
#' @export |
|
193 |
#' @rdname scale_tol_muted |
|
194 |
scale_color_muted <- scale_colour_muted |
|
195 | ||
196 |
#' @export |
|
197 |
#' @rdname scale_tol_muted |
|
198 |
scale_fill_muted <- function(..., reverse = FALSE, aesthetics = "fill") { |
|
199 | 4x |
scale_discrete(aesthetics, "muted", reverse = reverse, ...) |
200 |
} |
|
201 | ||
202 |
#' @export |
|
203 |
#' @rdname scale_tol_muted |
|
204 |
scale_edge_colour_muted <- function(..., reverse = FALSE, |
|
205 |
aesthetics = "edge_colour") { |
|
206 | 8x |
scale_discrete(aesthetics, "muted", reverse = reverse, ...) |
207 |
} |
|
208 | ||
209 |
#' @export |
|
210 |
#' @rdname scale_tol_muted |
|
211 |
scale_edge_color_muted <- scale_edge_colour_muted |
|
212 | ||
213 |
#' @export |
|
214 |
#' @rdname scale_tol_muted |
|
215 |
scale_edge_fill_muted <- function(..., reverse = FALSE, |
|
216 |
aesthetics = "edge_fill") { |
|
217 | 4x |
scale_discrete(aesthetics, "muted", reverse = reverse, ...) |
218 |
} |
|
219 | ||
220 |
## Medium contrast ------------------------------------------------------------- |
|
221 |
#' Paul Tol's *medium contrast* Discrete Color Scheme |
|
222 |
#' |
|
223 |
#' @inheritParams scale_tol_bright |
|
224 |
#' @inheritSection tol Qualitative Color Schemes |
|
225 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
226 |
#' @references |
|
227 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
228 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
229 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
230 |
#' @example inst/examples/ex-tol-discrete.R |
|
231 |
#' @author N. Frerebeau |
|
232 |
#' @family qualitative color schemes |
|
233 |
#' @family Paul Tol's color schemes |
|
234 |
#' @name scale_tol_mediumcontrast |
|
235 |
#' @rdname scale_tol_mediumcontrast |
|
236 |
NULL |
|
237 | ||
238 |
#' @export |
|
239 |
#' @rdname scale_tol_mediumcontrast |
|
240 |
scale_colour_mediumcontrast <- function(..., reverse = FALSE, |
|
241 |
aesthetics = "colour") { |
|
242 | 5x |
scale_discrete(aesthetics, "mediumcontrast", reverse = reverse, ...) |
243 |
} |
|
244 | ||
245 |
#' @export |
|
246 |
#' @rdname scale_tol_mediumcontrast |
|
247 |
scale_color_mediumcontrast <- scale_colour_mediumcontrast |
|
248 | ||
249 |
#' @export |
|
250 |
#' @rdname scale_tol_mediumcontrast |
|
251 |
scale_fill_mediumcontrast <- function(..., reverse = FALSE, |
|
252 |
aesthetics = "fill") { |
|
253 | 3x |
scale_discrete(aesthetics, "mediumcontrast", reverse = reverse, ...) |
254 |
} |
|
255 | ||
256 |
#' @export |
|
257 |
#' @rdname scale_tol_mediumcontrast |
|
258 |
scale_edge_colour_mediumcontrast <- function(..., reverse = FALSE, |
|
259 |
aesthetics = "edge_colour") { |
|
260 | 5x |
scale_discrete(aesthetics, "mediumcontrast", reverse = reverse, ...) |
261 |
} |
|
262 | ||
263 |
#' @export |
|
264 |
#' @rdname scale_tol_mediumcontrast |
|
265 |
scale_edge_color_mediumcontrast <- scale_edge_colour_mediumcontrast |
|
266 | ||
267 |
#' @export |
|
268 |
#' @rdname scale_tol_mediumcontrast |
|
269 |
scale_edge_fill_mediumcontrast <- function(..., reverse = FALSE, |
|
270 |
aesthetics = "edge_fill") { |
|
271 | 3x |
scale_discrete(aesthetics, "mediumcontrast", reverse = reverse, ...) |
272 |
} |
|
273 | ||
274 |
## Pale ------------------------------------------------------------------------ |
|
275 |
#' Paul Tol's *pale* Discrete Color Scheme |
|
276 |
#' |
|
277 |
#' @inheritParams scale_tol_bright |
|
278 |
#' @inheritSection tol Qualitative Color Schemes |
|
279 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
280 |
#' @references |
|
281 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
282 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
283 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
284 |
#' @example inst/examples/ex-tol-discrete.R |
|
285 |
#' @author N. Frerebeau |
|
286 |
#' @family qualitative color schemes |
|
287 |
#' @family Paul Tol's color schemes |
|
288 |
#' @name scale_tol_pale |
|
289 |
#' @rdname scale_tol_pale |
|
290 |
NULL |
|
291 | ||
292 |
#' @export |
|
293 |
#' @rdname scale_tol_pale |
|
294 |
scale_colour_pale <- function(..., reverse = FALSE, aesthetics = "colour") { |
|
295 | 5x |
scale_discrete(aesthetics, "pale", reverse = reverse, ...) |
296 |
} |
|
297 | ||
298 |
#' @export |
|
299 |
#' @rdname scale_tol_pale |
|
300 |
scale_color_pale <- scale_colour_pale |
|
301 | ||
302 |
#' @export |
|
303 |
#' @rdname scale_tol_pale |
|
304 |
scale_fill_pale <- function(..., reverse = FALSE, aesthetics = "fill") { |
|
305 | 3x |
scale_discrete(aesthetics, "pale", reverse = reverse, ...) |
306 |
} |
|
307 | ||
308 |
#' @export |
|
309 |
#' @rdname scale_tol_pale |
|
310 |
scale_edge_colour_pale <- function(..., reverse = FALSE, |
|
311 |
aesthetics = "edge_colour") { |
|
312 | 5x |
scale_discrete(aesthetics, "pale", reverse = reverse, ...) |
313 |
} |
|
314 | ||
315 |
#' @export |
|
316 |
#' @rdname scale_tol_pale |
|
317 |
scale_edge_color_pale <- scale_edge_colour_pale |
|
318 | ||
319 |
#' @export |
|
320 |
#' @rdname scale_tol_pale |
|
321 |
scale_edge_fill_pale <- function(..., reverse = FALSE, |
|
322 |
aesthetics = "edge_fill") { |
|
323 | 3x |
scale_discrete(aesthetics, "pale", reverse = reverse, ...) |
324 |
} |
|
325 | ||
326 |
## Dark ------------------------------------------------------------------------ |
|
327 |
#' Paul Tol's *dark* Discrete Color Scheme |
|
328 |
#' |
|
329 |
#' @inheritParams scale_tol_bright |
|
330 |
#' @inheritSection tol Qualitative Color Schemes |
|
331 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
332 |
#' @references |
|
333 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
334 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
335 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
336 |
#' @example inst/examples/ex-tol-discrete.R |
|
337 |
#' @author N. Frerebeau |
|
338 |
#' @family qualitative color schemes |
|
339 |
#' @family Paul Tol's color schemes |
|
340 |
#' @name scale_tol_dark |
|
341 |
#' @rdname scale_tol_dark |
|
342 |
NULL |
|
343 | ||
344 |
#' @export |
|
345 |
#' @rdname scale_tol_dark |
|
346 |
scale_colour_dark <- function(..., reverse = FALSE, aesthetics = "colour") { |
|
347 | 5x |
scale_discrete(aesthetics, "dark", reverse = reverse, ...) |
348 |
} |
|
349 | ||
350 |
#' @export |
|
351 |
#' @rdname scale_tol_dark |
|
352 |
scale_color_dark <- scale_colour_dark |
|
353 | ||
354 |
#' @export |
|
355 |
#' @rdname scale_tol_dark |
|
356 |
scale_fill_dark <- function(..., reverse = FALSE, aesthetics = "fill") { |
|
357 | 3x |
scale_discrete(aesthetics, "dark", reverse = reverse, ...) |
358 |
} |
|
359 | ||
360 |
#' @export |
|
361 |
#' @rdname scale_tol_dark |
|
362 |
scale_edge_colour_dark <- function(..., reverse = FALSE, |
|
363 |
aesthetics = "edge_colour") { |
|
364 | 5x |
scale_discrete(aesthetics, "dark", reverse = reverse, ...) |
365 |
} |
|
366 | ||
367 |
#' @export |
|
368 |
#' @rdname scale_tol_dark |
|
369 |
scale_edge_color_dark <- scale_edge_colour_dark |
|
370 | ||
371 |
#' @export |
|
372 |
#' @rdname scale_tol_dark |
|
373 |
scale_edge_fill_dark <- function(..., reverse = FALSE, |
|
374 |
aesthetics = "edge_fill") { |
|
375 | 3x |
scale_discrete(aesthetics, "dark", reverse = reverse, ...) |
376 |
} |
|
377 | ||
378 |
## Light ----------------------------------------------------------------------- |
|
379 |
#' Paul Tol's *light* Discrete Color Scheme |
|
380 |
#' |
|
381 |
#' @inheritParams scale_tol_bright |
|
382 |
#' @inheritSection tol Qualitative Color Schemes |
|
383 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
384 |
#' @references |
|
385 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
386 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
387 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
388 |
#' @example inst/examples/ex-tol-discrete.R |
|
389 |
#' @author N. Frerebeau |
|
390 |
#' @family qualitative color schemes |
|
391 |
#' @family Paul Tol's color schemes |
|
392 |
#' @name scale_tol_light |
|
393 |
#' @rdname scale_tol_light |
|
394 |
NULL |
|
395 | ||
396 |
#' @export |
|
397 |
#' @rdname scale_tol_light |
|
398 |
scale_colour_light <- function(..., reverse = FALSE, aesthetics = "colour") { |
|
399 | 5x |
scale_discrete(aesthetics, "light", reverse = reverse, ...) |
400 |
} |
|
401 | ||
402 |
#' @export |
|
403 |
#' @rdname scale_tol_light |
|
404 |
scale_color_light <- scale_colour_light |
|
405 | ||
406 |
#' @export |
|
407 |
#' @rdname scale_tol_light |
|
408 |
scale_fill_light <- function(..., reverse = FALSE, aesthetics = "fill") { |
|
409 | 3x |
scale_discrete(aesthetics, "light", reverse = reverse, ...) |
410 |
} |
|
411 | ||
412 |
#' @export |
|
413 |
#' @rdname scale_tol_light |
|
414 |
scale_edge_colour_light <- function(..., reverse = FALSE, |
|
415 |
aesthetics = "edge_colour") { |
|
416 | 5x |
scale_discrete(aesthetics, "light", reverse = reverse, ...) |
417 |
} |
|
418 | ||
419 |
#' @export |
|
420 |
#' @rdname scale_tol_light |
|
421 |
scale_edge_color_light <- scale_edge_colour_light |
|
422 | ||
423 |
#' @export |
|
424 |
#' @rdname scale_tol_light |
|
425 |
scale_edge_fill_light <- function(..., reverse = FALSE, |
|
426 |
aesthetics = "edge_fill") { |
|
427 | 3x |
scale_discrete(aesthetics, "light", reverse = reverse, ...) |
428 |
} |
|
429 | ||
430 |
## Discrete Rainbow ------------------------------------------------------------ |
|
431 |
#' Paul Tol's *discrete rainbow* Sequential Color Scheme |
|
432 |
#' |
|
433 |
#' @inheritParams scale_tol_bright |
|
434 |
#' @inheritSection tol Sequential Color Schemes |
|
435 |
#' @inheritSection tol Rainbow Color Scheme |
|
436 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
437 |
#' @references |
|
438 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
439 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
440 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
441 |
#' @example inst/examples/ex-tol-discrete.R |
|
442 |
#' @author N. Frerebeau |
|
443 |
#' @family qualitative color schemes |
|
444 |
#' @family Paul Tol's color schemes |
|
445 |
#' @name scale_tol_discreterainbow |
|
446 |
#' @rdname scale_tol_discreterainbow |
|
447 |
NULL |
|
448 | ||
449 |
#' @export |
|
450 |
#' @rdname scale_tol_discreterainbow |
|
451 |
scale_colour_discreterainbow <- function(..., reverse = FALSE, |
|
452 |
aesthetics = "colour") { |
|
453 | 6x |
scale_discrete(aesthetics, "discreterainbow", reverse = reverse, ...) |
454 |
} |
|
455 | ||
456 |
#' @export |
|
457 |
#' @rdname scale_tol_discreterainbow |
|
458 |
scale_color_discreterainbow <- scale_colour_discreterainbow |
|
459 | ||
460 |
#' @export |
|
461 |
#' @rdname scale_tol_discreterainbow |
|
462 |
scale_fill_discreterainbow <- function(..., reverse = FALSE, |
|
463 |
aesthetics = "fill") { |
|
464 | 3x |
scale_discrete(aesthetics, "discreterainbow", reverse = reverse, ...) |
465 |
} |
|
466 | ||
467 |
#' @export |
|
468 |
#' @rdname scale_tol_discreterainbow |
|
469 |
scale_edge_colour_discreterainbow <- function(..., reverse = FALSE, |
|
470 |
aesthetics = "edge_colour") { |
|
471 | 6x |
scale_discrete(aesthetics, "discreterainbow", reverse = reverse, ...) |
472 |
} |
|
473 | ||
474 |
#' @export |
|
475 |
#' @rdname scale_tol_discreterainbow |
|
476 |
scale_edge_color_discreterainbow <- scale_edge_colour_discreterainbow |
|
477 | ||
478 |
#' @export |
|
479 |
#' @rdname scale_tol_discreterainbow |
|
480 |
scale_edge_fill_discreterainbow <- function(..., reverse = FALSE, |
|
481 |
aesthetics = "edge_fill") { |
|
482 | 3x |
scale_discrete(aesthetics, "discreterainbow", reverse = reverse, ...) |
483 |
} |
|
484 | ||
485 |
# Diverging ==================================================================== |
|
486 |
## Sunset ---------------------------------------------------------------------- |
|
487 |
#' Paul Tol's *sunset* Diverging Color Scheme |
|
488 |
#' |
|
489 |
#' @param ... Arguments passed to [ggplot2::continuous_scale()]. |
|
490 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
491 |
#' vector of colors be reversed? |
|
492 |
#' @param range A length-two [`numeric`] vector specifying the |
|
493 |
#' fraction of the scheme's color domain to keep. |
|
494 |
#' @param midpoint A length-one [`numeric`] vector giving the midpoint |
|
495 |
#' (in data value) of the diverging scale. Defaults to `0`. |
|
496 |
#' @param discrete A [`logical`] scalar: should the color scheme be |
|
497 |
#' used as a discrete scale? If `TRUE`, it is a departure from Paul Tol's |
|
498 |
#' recommendations and likely a very poor use of color. |
|
499 |
#' @param aesthetics A [`character`] string or vector of character |
|
500 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
501 |
#' @inheritSection tol Diverging Color Schemes |
|
502 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
503 |
#' @references |
|
504 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
505 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
506 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
507 |
#' @example inst/examples/ex-tol-diverging.R |
|
508 |
#' @author N. Frerebeau |
|
509 |
#' @family diverging color schemes |
|
510 |
#' @family Paul Tol's color schemes |
|
511 |
#' @name scale_tol_sunset |
|
512 |
#' @rdname scale_tol_sunset |
|
513 |
NULL |
|
514 | ||
515 |
#' @export |
|
516 |
#' @rdname scale_tol_sunset |
|
517 |
scale_colour_sunset <- function(..., reverse = FALSE, range = c(0, 1), |
|
518 |
midpoint = 0, discrete = FALSE, |
|
519 |
aesthetics = "colour") { |
|
520 | 7x |
if (discrete) { |
521 | ! |
scale_discrete(aesthetics, "sunset", reverse = reverse, ...) |
522 |
} else { |
|
523 | 7x |
scale_continuous(aesthetics, "sunset", reverse = reverse, range = range, |
524 | 7x |
midpoint = midpoint, ...) |
525 |
} |
|
526 |
} |
|
527 | ||
528 |
#' @export |
|
529 |
#' @rdname scale_tol_sunset |
|
530 |
scale_color_sunset <- scale_colour_sunset |
|
531 | ||
532 |
#' @export |
|
533 |
#' @rdname scale_tol_sunset |
|
534 |
scale_fill_sunset <- function(..., reverse = FALSE, range = c(0, 1), |
|
535 |
midpoint = 0, discrete = FALSE, |
|
536 |
aesthetics = "fill") { |
|
537 | 5x |
if (discrete) { |
538 | ! |
scale_discrete(aesthetics, "sunset", reverse = reverse, ...) |
539 |
} else { |
|
540 | 5x |
scale_continuous(aesthetics, "sunset", reverse = reverse, range = range, |
541 | 5x |
midpoint = midpoint, ...) |
542 |
} |
|
543 |
} |
|
544 | ||
545 |
#' @export |
|
546 |
#' @rdname scale_tol_sunset |
|
547 |
scale_edge_colour_sunset <- function(..., reverse = FALSE, range = c(0, 1), |
|
548 |
midpoint = 0, discrete = FALSE, |
|
549 |
aesthetics = "edge_colour") { |
|
550 | 7x |
if (discrete) { |
551 | ! |
scale_discrete(aesthetics, "sunset", reverse = reverse, ...) |
552 |
} else { |
|
553 | 7x |
scale_continuous(aesthetics, "sunset", guide = "edge_colourbar", |
554 | 7x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
555 |
} |
|
556 |
} |
|
557 | ||
558 |
#' @export |
|
559 |
#' @rdname scale_tol_sunset |
|
560 |
scale_edge_color_sunset <- scale_edge_colour_sunset |
|
561 | ||
562 |
#' @export |
|
563 |
#' @rdname scale_tol_sunset |
|
564 |
scale_edge_fill_sunset <- function(..., reverse = FALSE, range = c(0, 1), |
|
565 |
midpoint = 0, discrete = FALSE, |
|
566 |
aesthetics = "edge_fill") { |
|
567 | 5x |
if (discrete) { |
568 | ! |
scale_discrete(aesthetics, "sunset", reverse = reverse, ...) |
569 |
} else { |
|
570 | 5x |
scale_continuous(aesthetics, "sunset", guide = "edge_colourbar", |
571 | 5x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
572 |
} |
|
573 |
} |
|
574 | ||
575 |
## Nightfall ---------------------------------------------------------------------- |
|
576 |
#' Paul Tol's *nightfall* Diverging Color Scheme |
|
577 |
#' |
|
578 |
#' @inheritParams scale_tol_sunset |
|
579 |
#' @inheritSection tol Diverging Color Schemes |
|
580 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
581 |
#' @references |
|
582 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
583 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
584 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
585 |
#' @example inst/examples/ex-tol-diverging.R |
|
586 |
#' @author N. Frerebeau |
|
587 |
#' @family diverging color schemes |
|
588 |
#' @family Paul Tol's color schemes |
|
589 |
#' @name scale_tol_nightfall |
|
590 |
#' @rdname scale_tol_nightfall |
|
591 |
NULL |
|
592 | ||
593 |
#' @export |
|
594 |
#' @rdname scale_tol_nightfall |
|
595 |
scale_colour_nightfall <- function(..., reverse = FALSE, range = c(0, 1), |
|
596 |
midpoint = 0, discrete = FALSE, |
|
597 |
aesthetics = "colour") { |
|
598 | 7x |
if (discrete) { |
599 | ! |
scale_discrete(aesthetics, "nightfall", reverse = reverse, ...) |
600 |
} else { |
|
601 | 7x |
scale_continuous(aesthetics, "nightfall", reverse = reverse, range = range, |
602 | 7x |
midpoint = midpoint, ...) |
603 |
} |
|
604 |
} |
|
605 | ||
606 |
#' @export |
|
607 |
#' @rdname scale_tol_nightfall |
|
608 |
scale_color_nightfall <- scale_colour_nightfall |
|
609 | ||
610 |
#' @export |
|
611 |
#' @rdname scale_tol_nightfall |
|
612 |
scale_fill_nightfall <- function(..., reverse = FALSE, range = c(0, 1), |
|
613 |
midpoint = 0, discrete = FALSE, |
|
614 |
aesthetics = "fill") { |
|
615 | 5x |
if (discrete) { |
616 | ! |
scale_discrete(aesthetics, "nightfall", reverse = reverse, ...) |
617 |
} else { |
|
618 | 5x |
scale_continuous(aesthetics, "nightfall", reverse = reverse, range = range, |
619 | 5x |
midpoint = midpoint, ...) |
620 |
} |
|
621 |
} |
|
622 | ||
623 |
#' @export |
|
624 |
#' @rdname scale_tol_nightfall |
|
625 |
scale_edge_colour_nightfall <- function(..., reverse = FALSE, range = c(0, 1), |
|
626 |
midpoint = 0, discrete = FALSE, |
|
627 |
aesthetics = "edge_colour") { |
|
628 | 7x |
if (discrete) { |
629 | ! |
scale_discrete(aesthetics, "nightfall", reverse = reverse, ...) |
630 |
} else { |
|
631 | 7x |
scale_continuous(aesthetics, "nightfall", guide = "edge_colourbar", |
632 | 7x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
633 |
} |
|
634 |
} |
|
635 | ||
636 |
#' @export |
|
637 |
#' @rdname scale_tol_nightfall |
|
638 |
scale_edge_color_nightfall <- scale_edge_colour_nightfall |
|
639 | ||
640 |
#' @export |
|
641 |
#' @rdname scale_tol_nightfall |
|
642 |
scale_edge_fill_nightfall <- function(..., reverse = FALSE, range = c(0, 1), |
|
643 |
midpoint = 0, discrete = FALSE, |
|
644 |
aesthetics = "edge_fill") { |
|
645 | 5x |
if (discrete) { |
646 | ! |
scale_discrete(aesthetics, "nightfall", reverse = reverse, ...) |
647 |
} else { |
|
648 | 5x |
scale_continuous(aesthetics, "nightfall", guide = "edge_colourbar", |
649 | 5x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
650 |
} |
|
651 |
} |
|
652 | ||
653 |
## BuRd ------------------------------------------------------------------------ |
|
654 |
#' Paul Tol's *BuRd* Diverging Color Scheme |
|
655 |
#' |
|
656 |
#' @inheritParams scale_tol_sunset |
|
657 |
#' @inheritSection tol Diverging Color Schemes |
|
658 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
659 |
#' @references |
|
660 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
661 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
662 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
663 |
#' @example inst/examples/ex-tol-diverging.R |
|
664 |
#' @author N. Frerebeau |
|
665 |
#' @family diverging color schemes |
|
666 |
#' @family Paul Tol's color schemes |
|
667 |
#' @name scale_tol_BuRd |
|
668 |
#' @rdname scale_tol_BuRd |
|
669 |
NULL |
|
670 | ||
671 |
#' @export |
|
672 |
#' @rdname scale_tol_BuRd |
|
673 |
scale_colour_BuRd <- function(..., reverse = FALSE, range = c(0, 1), |
|
674 |
midpoint = 0, discrete = FALSE, |
|
675 |
aesthetics = "colour") { |
|
676 | 8x |
if (discrete) { |
677 | ! |
scale_discrete(aesthetics, "BuRd", reverse = reverse, ...) |
678 |
} else { |
|
679 | 8x |
scale_continuous(aesthetics, "BuRd", reverse = reverse, range = range, |
680 | 8x |
midpoint = midpoint, ...) |
681 |
} |
|
682 |
} |
|
683 | ||
684 |
#' @export |
|
685 |
#' @rdname scale_tol_BuRd |
|
686 |
scale_color_BuRd <- scale_colour_BuRd |
|
687 | ||
688 |
#' @export |
|
689 |
#' @rdname scale_tol_BuRd |
|
690 |
scale_fill_BuRd <- function(..., reverse = FALSE, range = c(0, 1), |
|
691 |
midpoint = 0, discrete = FALSE, |
|
692 |
aesthetics = "fill") { |
|
693 | 5x |
if (discrete) { |
694 | ! |
scale_discrete(aesthetics, "BuRd", reverse = reverse, ...) |
695 |
} else { |
|
696 | 5x |
scale_continuous(aesthetics, "BuRd", reverse = reverse, range = range, |
697 | 5x |
midpoint = midpoint, ...) |
698 |
} |
|
699 |
} |
|
700 | ||
701 |
#' @export |
|
702 |
#' @rdname scale_tol_BuRd |
|
703 |
scale_edge_colour_BuRd <- function(..., reverse = FALSE, range = c(0, 1), |
|
704 |
midpoint = 0, discrete = FALSE, |
|
705 |
aesthetics = "edge_colour") { |
|
706 | 8x |
if (discrete) { |
707 | ! |
scale_discrete(aesthetics, "BuRd", reverse = reverse, ...) |
708 |
} else { |
|
709 | 8x |
scale_continuous(aesthetics, "BuRd", guide = "edge_colourbar", |
710 | 8x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
711 |
} |
|
712 |
} |
|
713 | ||
714 |
#' @export |
|
715 |
#' @rdname scale_tol_BuRd |
|
716 |
scale_edge_color_BuRd <- scale_edge_colour_BuRd |
|
717 | ||
718 |
#' @export |
|
719 |
#' @rdname scale_tol_BuRd |
|
720 |
scale_edge_fill_BuRd <- function(..., reverse = FALSE, range = c(0, 1), |
|
721 |
midpoint = 0, discrete = FALSE, |
|
722 |
aesthetics = "edge_fill") { |
|
723 | 5x |
if (discrete) { |
724 | ! |
scale_discrete(aesthetics, "BuRd", reverse = reverse, ...) |
725 |
} else { |
|
726 | 5x |
scale_continuous(aesthetics, "BuRd", guide = "edge_colourbar", |
727 | 5x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
728 |
} |
|
729 |
} |
|
730 | ||
731 |
## PRGn ------------------------------------------------------------------------ |
|
732 |
#' Paul Tol's *PRGn* Diverging Color Scheme |
|
733 |
#' |
|
734 |
#' @inheritParams scale_tol_sunset |
|
735 |
#' @inheritSection tol Diverging Color Schemes |
|
736 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
737 |
#' @references |
|
738 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
739 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
740 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
741 |
#' @example inst/examples/ex-tol-diverging.R |
|
742 |
#' @author N. Frerebeau |
|
743 |
#' @family diverging color schemes |
|
744 |
#' @family Paul Tol's color schemes |
|
745 |
#' @name scale_tol_PRGn |
|
746 |
#' @rdname scale_tol_PRGn |
|
747 |
NULL |
|
748 | ||
749 |
#' @export |
|
750 |
#' @rdname scale_tol_PRGn |
|
751 |
scale_colour_PRGn <- function(..., reverse = FALSE, range = c(0, 1), |
|
752 |
midpoint = 0, discrete = FALSE, |
|
753 |
aesthetics = "colour") { |
|
754 | 8x |
if (discrete) { |
755 | ! |
scale_discrete(aesthetics, "PRGn", reverse = reverse, ...) |
756 |
} else { |
|
757 | 8x |
scale_continuous(aesthetics, "PRGn", reverse = reverse, range = range, |
758 | 8x |
midpoint = midpoint, ...) |
759 |
} |
|
760 |
} |
|
761 | ||
762 |
#' @export |
|
763 |
#' @rdname scale_tol_PRGn |
|
764 |
scale_color_PRGn <- scale_colour_PRGn |
|
765 | ||
766 |
#' @export |
|
767 |
#' @rdname scale_tol_PRGn |
|
768 |
scale_fill_PRGn <- function(..., reverse = FALSE, range = c(0, 1), |
|
769 |
midpoint = 0, discrete = FALSE, |
|
770 |
aesthetics = "fill") { |
|
771 | 5x |
if (discrete) { |
772 | ! |
scale_discrete(aesthetics, "PRGn", reverse = reverse, ...) |
773 |
} else { |
|
774 | 5x |
scale_continuous(aesthetics, "PRGn", reverse = reverse, range = range, |
775 | 5x |
midpoint = midpoint, ...) |
776 |
} |
|
777 |
} |
|
778 | ||
779 |
#' @export |
|
780 |
#' @rdname scale_tol_PRGn |
|
781 |
scale_edge_colour_PRGn <- function(..., reverse = FALSE, range = c(0, 1), |
|
782 |
midpoint = 0, discrete = FALSE, |
|
783 |
aesthetics = "edge_colour") { |
|
784 | 8x |
if (discrete) { |
785 | ! |
scale_discrete(aesthetics, "PRGn", reverse = reverse, ...) |
786 |
} else { |
|
787 | 8x |
scale_continuous(aesthetics, "PRGn", guide = "edge_colourbar", |
788 | 8x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
789 |
} |
|
790 |
} |
|
791 | ||
792 |
#' @export |
|
793 |
#' @rdname scale_tol_PRGn |
|
794 |
scale_edge_color_PRGn <- scale_edge_colour_PRGn |
|
795 | ||
796 |
#' @export |
|
797 |
#' @rdname scale_tol_PRGn |
|
798 |
scale_edge_fill_PRGn <- function(..., reverse = FALSE, range = c(0, 1), |
|
799 |
midpoint = 0, discrete = FALSE, |
|
800 |
aesthetics = "edge_fill") { |
|
801 | 5x |
if (discrete) { |
802 | ! |
scale_discrete(aesthetics, "PRGn", reverse = reverse, ...) |
803 |
} else { |
|
804 | 5x |
scale_continuous(aesthetics, "PRGn", guide = "edge_colourbar", |
805 | 5x |
reverse = reverse, range = range, midpoint = midpoint, ...) |
806 |
} |
|
807 |
} |
|
808 | ||
809 |
# Sequential =================================================================== |
|
810 |
## YlOrBr ---------------------------------------------------------------------- |
|
811 |
#' Paul Tol's *YlOrBr* Sequential Color Scheme |
|
812 |
#' |
|
813 |
#' @param ... Arguments passed to [ggplot2::continuous_scale()]. |
|
814 |
#' @param reverse A [`logical`] scalar. Should the resulting |
|
815 |
#' vector of colors be reversed? |
|
816 |
#' @param range A length-two [`numeric`] vector specifying the |
|
817 |
#' fraction of the scheme's color domain to keep. |
|
818 |
#' @param aesthetics A [`character`] string or vector of character |
|
819 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
820 |
#' @param discrete A [`logical`] scalar: should the color scheme be |
|
821 |
#' used as a discrete scale? If `TRUE`, it is a departure from Paul Tol's |
|
822 |
#' recommendations and likely a very poor use of color. |
|
823 |
#' @inheritSection tol Sequential Color Schemes |
|
824 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
825 |
#' @references |
|
826 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
827 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
828 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
829 |
#' @example inst/examples/ex-tol-sequential.R |
|
830 |
#' @author N. Frerebeau |
|
831 |
#' @family sequential color schemes |
|
832 |
#' @family Paul Tol's color schemes |
|
833 |
#' @name scale_tol_YlOrBr |
|
834 |
#' @rdname scale_tol_YlOrBr |
|
835 |
NULL |
|
836 | ||
837 |
#' @export |
|
838 |
#' @rdname scale_tol_YlOrBr |
|
839 |
scale_colour_YlOrBr <- function(..., reverse = FALSE, range = c(0, 1), |
|
840 |
discrete = FALSE, aesthetics = "colour") { |
|
841 | 7x |
if (discrete) { |
842 | 1x |
scale_discrete(aesthetics, "YlOrBr", reverse = reverse, ...) |
843 |
} else { |
|
844 | 6x |
scale_continuous(aesthetics, "YlOrBr", reverse = reverse, |
845 | 6x |
range = range, ...) |
846 |
} |
|
847 |
} |
|
848 | ||
849 |
#' @export |
|
850 |
#' @rdname scale_tol_YlOrBr |
|
851 |
scale_color_YlOrBr <- scale_colour_YlOrBr |
|
852 | ||
853 |
#' @export |
|
854 |
#' @rdname scale_tol_YlOrBr |
|
855 |
scale_fill_YlOrBr <- function(..., reverse = FALSE, range = c(0, 1), |
|
856 |
discrete = FALSE, aesthetics = "fill") { |
|
857 | 6x |
if (discrete) { |
858 | 1x |
scale_discrete(aesthetics, "YlOrBr", reverse = reverse, ...) |
859 |
} else { |
|
860 | 5x |
scale_continuous(aesthetics, "YlOrBr", reverse = reverse, |
861 | 5x |
range = range, ...) |
862 |
} |
|
863 |
} |
|
864 | ||
865 |
#' @export |
|
866 |
#' @rdname scale_tol_YlOrBr |
|
867 |
scale_edge_colour_YlOrBr <- function(..., reverse = FALSE, range = c(0, 1), |
|
868 |
discrete = FALSE, |
|
869 |
aesthetics = "edge_colour") { |
|
870 | 7x |
if (discrete) { |
871 | 1x |
scale_discrete(aesthetics, "YlOrBr", reverse = reverse, ...) |
872 |
} else { |
|
873 | 6x |
scale_continuous(aesthetics, "YlOrBr", guide = "edge_colourbar", |
874 | 6x |
reverse = reverse, range = range, ...) |
875 |
} |
|
876 |
} |
|
877 | ||
878 |
#' @export |
|
879 |
#' @rdname scale_tol_YlOrBr |
|
880 |
scale_edge_color_YlOrBr <- scale_edge_colour_YlOrBr |
|
881 | ||
882 |
#' @export |
|
883 |
#' @rdname scale_tol_YlOrBr |
|
884 |
scale_edge_fill_YlOrBr <- function(..., reverse = FALSE, range = c(0, 1), |
|
885 |
discrete = FALSE, |
|
886 |
aesthetics = "edge_fill") { |
|
887 | 6x |
if (discrete) { |
888 | 1x |
scale_discrete(aesthetics, "YlOrBr", reverse = reverse, ...) |
889 |
} else { |
|
890 | 5x |
scale_continuous(aesthetics, "YlOrBr", guide = "edge_colourbar", |
891 | 5x |
reverse = reverse, range = range, ...) |
892 |
} |
|
893 |
} |
|
894 | ||
895 |
## Iridescent ------------------------------------------------------------------ |
|
896 |
#' Paul Tol's *iridescent* Sequential Color Scheme |
|
897 |
#' |
|
898 |
#' @inheritParams scale_colour_YlOrBr |
|
899 |
#' @inheritSection tol Sequential Color Schemes |
|
900 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
901 |
#' @references |
|
902 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
903 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
904 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
905 |
#' @example inst/examples/ex-tol-sequential.R |
|
906 |
#' @author N. Frerebeau |
|
907 |
#' @family sequential color schemes |
|
908 |
#' @family Paul Tol's color schemes |
|
909 |
#' @name scale_tol_iridescent |
|
910 |
#' @rdname scale_tol_iridescent |
|
911 |
NULL |
|
912 | ||
913 |
#' @export |
|
914 |
#' @rdname scale_tol_iridescent |
|
915 |
scale_colour_iridescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
916 |
discrete = FALSE, aesthetics = "colour") { |
|
917 | 7x |
if (discrete) { |
918 | 1x |
scale_discrete(aesthetics, "iridescent", reverse = reverse, ...) |
919 |
} else { |
|
920 | 6x |
scale_continuous(aesthetics, "iridescent", reverse = reverse, |
921 | 6x |
range = range, ...) |
922 |
} |
|
923 |
} |
|
924 | ||
925 |
#' @export |
|
926 |
#' @rdname scale_tol_iridescent |
|
927 |
scale_color_iridescent <- scale_colour_iridescent |
|
928 | ||
929 |
#' @export |
|
930 |
#' @rdname scale_tol_iridescent |
|
931 |
scale_fill_iridescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
932 |
discrete = FALSE, aesthetics = "fill") { |
|
933 | 4x |
if (discrete) { |
934 | 1x |
scale_discrete(aesthetics, "iridescent", reverse = reverse, ...) |
935 |
} else { |
|
936 | 3x |
scale_continuous(aesthetics, "iridescent", reverse = reverse, |
937 | 3x |
range = range, ...) |
938 |
} |
|
939 |
} |
|
940 | ||
941 |
#' @export |
|
942 |
#' @rdname scale_tol_iridescent |
|
943 |
scale_edge_colour_iridescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
944 |
discrete = FALSE, |
|
945 |
aesthetics = "edge_colour") { |
|
946 | 7x |
if (discrete) { |
947 | 1x |
scale_discrete(aesthetics, "iridescent", reverse = reverse, ...) |
948 |
} else { |
|
949 | 6x |
scale_continuous(aesthetics, "iridescent", guide = "edge_colourbar", |
950 | 6x |
reverse = reverse, range = range, ...) |
951 |
} |
|
952 |
} |
|
953 | ||
954 |
#' @export |
|
955 |
#' @rdname scale_tol_iridescent |
|
956 |
scale_edge_color_iridescent <- scale_edge_colour_iridescent |
|
957 | ||
958 |
#' @export |
|
959 |
#' @rdname scale_tol_iridescent |
|
960 |
scale_edge_fill_iridescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
961 |
discrete = FALSE, |
|
962 |
aesthetics = "edge_fill") { |
|
963 | 4x |
if (discrete) { |
964 | 1x |
scale_discrete(aesthetics, "iridescent", reverse = reverse, ...) |
965 |
} else { |
|
966 | 3x |
scale_continuous(aesthetics, "iridescent", guide = "edge_colourbar", |
967 | 3x |
reverse = reverse, range = range, ...) |
968 |
} |
|
969 |
} |
|
970 | ||
971 |
## Incandescent ------------------------------------------------------------------ |
|
972 |
#' Paul Tol's *incandescent* Sequential Color Scheme |
|
973 |
#' |
|
974 |
#' @inheritParams scale_colour_YlOrBr |
|
975 |
#' @inheritSection tol Sequential Color Schemes |
|
976 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
977 |
#' @references |
|
978 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
979 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
980 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
981 |
#' @example inst/examples/ex-tol-sequential.R |
|
982 |
#' @author N. Frerebeau |
|
983 |
#' @family sequential color schemes |
|
984 |
#' @family Paul Tol's color schemes |
|
985 |
#' @name scale_tol_incandescent |
|
986 |
#' @rdname scale_tol_incandescent |
|
987 |
NULL |
|
988 | ||
989 |
#' @export |
|
990 |
#' @rdname scale_tol_incandescent |
|
991 |
scale_colour_incandescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
992 |
discrete = FALSE, aesthetics = "colour") { |
|
993 | 7x |
if (discrete) { |
994 | 1x |
scale_discrete(aesthetics, "incandescent", reverse = reverse, ...) |
995 |
} else { |
|
996 | 6x |
scale_continuous(aesthetics, "incandescent", reverse = reverse, |
997 | 6x |
range = range, ...) |
998 |
} |
|
999 |
} |
|
1000 | ||
1001 |
#' @export |
|
1002 |
#' @rdname scale_tol_incandescent |
|
1003 |
scale_color_incandescent <- scale_colour_incandescent |
|
1004 | ||
1005 |
#' @export |
|
1006 |
#' @rdname scale_tol_incandescent |
|
1007 |
scale_fill_incandescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
1008 |
discrete = FALSE, aesthetics = "fill") { |
|
1009 | 4x |
if (discrete) { |
1010 | 1x |
scale_discrete(aesthetics, "incandescent", reverse = reverse, ...) |
1011 |
} else { |
|
1012 | 3x |
scale_continuous(aesthetics, "incandescent", reverse = reverse, |
1013 | 3x |
range = range, ...) |
1014 |
} |
|
1015 |
} |
|
1016 | ||
1017 |
#' @export |
|
1018 |
#' @rdname scale_tol_incandescent |
|
1019 |
scale_edge_colour_incandescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
1020 |
discrete = FALSE, |
|
1021 |
aesthetics = "edge_colour") { |
|
1022 | 7x |
if (discrete) { |
1023 | 1x |
scale_discrete(aesthetics, "incandescent", reverse = reverse, ...) |
1024 |
} else { |
|
1025 | 6x |
scale_continuous(aesthetics, "incandescent", guide = "edge_colourbar", |
1026 | 6x |
reverse = reverse, range = range, ...) |
1027 |
} |
|
1028 |
} |
|
1029 | ||
1030 |
#' @export |
|
1031 |
#' @rdname scale_tol_incandescent |
|
1032 |
scale_edge_color_incandescent <- scale_edge_colour_incandescent |
|
1033 | ||
1034 |
#' @export |
|
1035 |
#' @rdname scale_tol_incandescent |
|
1036 |
scale_edge_fill_incandescent <- function(..., reverse = FALSE, range = c(0, 1), |
|
1037 |
discrete = FALSE, |
|
1038 |
aesthetics = "edge_fill") { |
|
1039 | 4x |
if (discrete) { |
1040 | 1x |
scale_discrete(aesthetics, "incandescent", reverse = reverse, ...) |
1041 |
} else { |
|
1042 | 3x |
scale_continuous(aesthetics, "incandescent", guide = "edge_colourbar", |
1043 | 3x |
reverse = reverse, range = range, ...) |
1044 |
} |
|
1045 |
} |
|
1046 | ||
1047 |
## Smooth Rainbow -------------------------------------------------------------- |
|
1048 |
#' Paul Tol's *smooth rainbow* Sequential Color Scheme |
|
1049 |
#' |
|
1050 |
#' @inheritParams scale_colour_YlOrBr |
|
1051 |
#' @inheritSection tol Sequential Color Schemes |
|
1052 |
#' @inheritSection tol Rainbow Color Scheme |
|
1053 |
#' @return A [continuous][ggplot2::continuous_scale] scale. |
|
1054 |
#' @references |
|
1055 |
#' Tol, P. (2018). *Colour Schemes*. SRON. Technical Note No. |
|
1056 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
1057 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
1058 |
#' @example inst/examples/ex-tol-sequential.R |
|
1059 |
#' @author N. Frerebeau |
|
1060 |
#' @family sequential color schemes |
|
1061 |
#' @family Paul Tol's color schemes |
|
1062 |
#' @name scale_tol_smoothrainbow |
|
1063 |
#' @rdname scale_tol_smoothrainbow |
|
1064 |
NULL |
|
1065 | ||
1066 |
#' @export |
|
1067 |
#' @rdname scale_tol_smoothrainbow |
|
1068 |
scale_colour_smoothrainbow <- function(..., reverse = FALSE, range = c(0, 1), |
|
1069 |
discrete = FALSE, aesthetics = "colour") { |
|
1070 | 7x |
if (discrete) { |
1071 | 1x |
scale_discrete(aesthetics, "smoothrainbow", reverse = reverse, ...) |
1072 |
} else { |
|
1073 | 6x |
scale_continuous(aesthetics, "smoothrainbow", reverse = reverse, |
1074 | 6x |
range = range, ...) |
1075 |
} |
|
1076 |
} |
|
1077 | ||
1078 |
#' @export |
|
1079 |
#' @rdname scale_tol_smoothrainbow |
|
1080 |
scale_color_smoothrainbow <- scale_colour_smoothrainbow |
|
1081 | ||
1082 |
#' @export |
|
1083 |
#' @rdname scale_tol_smoothrainbow |
|
1084 |
scale_fill_smoothrainbow <- function(..., reverse = FALSE, range = c(0, 1), |
|
1085 |
discrete = FALSE, aesthetics = "fill") { |
|
1086 | 4x |
if (discrete) { |
1087 | 1x |
scale_discrete(aesthetics, "smooth rainbow", reverse = reverse, ...) |
1088 |
} else { |
|
1089 | 3x |
scale_continuous(aesthetics, "smooth rainbow", reverse = reverse, |
1090 | 3x |
range = range, ...) |
1091 |
} |
|
1092 |
} |
|
1093 | ||
1094 |
#' @export |
|
1095 |
#' @rdname scale_tol_smoothrainbow |
|
1096 |
scale_edge_colour_smoothrainbow <- function(..., reverse = FALSE, range = c(0, 1), |
|
1097 |
discrete = FALSE, |
|
1098 |
aesthetics = "edge_colour") { |
|
1099 | 7x |
if (discrete) { |
1100 | 1x |
scale_discrete(aesthetics, "smoothrainbow", reverse = reverse, ...) |
1101 |
} else { |
|
1102 | 6x |
scale_continuous(aesthetics, "smoothrainbow", guide = "edge_colourbar", |
1103 | 6x |
reverse = reverse, range = range, ...) |
1104 |
} |
|
1105 |
} |
|
1106 | ||
1107 |
#' @export |
|
1108 |
#' @rdname scale_tol_smoothrainbow |
|
1109 |
scale_edge_color_smoothrainbow <- scale_edge_colour_smoothrainbow |
|
1110 | ||
1111 |
#' @export |
|
1112 |
#' @rdname scale_tol_smoothrainbow |
|
1113 |
scale_edge_fill_smoothrainbow <- function(..., reverse = FALSE, range = c(0, 1), |
|
1114 |
discrete = FALSE, |
|
1115 |
aesthetics = "edge_fill") { |
|
1116 | 4x |
if (discrete) { |
1117 | 1x |
scale_discrete(aesthetics, "smoothrainbow", reverse = reverse, ...) |
1118 |
} else { |
|
1119 | 3x |
scale_continuous(aesthetics, "smoothrainbow", guide = "edge_colourbar", |
1120 | 3x |
reverse = reverse, range = range, ...) |
1121 |
} |
|
1122 |
} |
1 |
#' @include color.R |
|
2 |
NULL |
|
3 | ||
4 |
# Geologic Timescale =========================================================== |
|
5 |
#' Geologic Timescale Color Scheme for \pkg{ggplot2} and \pkg{ggraph} |
|
6 |
#' |
|
7 |
#' Provides the geologic timescale color scheme. |
|
8 |
#' @param ... Arguments passed on to [ggplot2::discrete_scale()]. |
|
9 |
#' @param lang A [`character`] string specifying the language for the |
|
10 |
#' color names (see details). It must be one of "`en`" (english, the |
|
11 |
#' default), "`fr`" (french) or `NULL`. If not `NULL`, the values will be |
|
12 |
#' matched based on the color names. |
|
13 |
#' @param aesthetics A [`character`] string or vector of character |
|
14 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
15 |
#' @details Values will be matched based on the geological unit names. |
|
16 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
17 |
#' @references |
|
18 |
#' \href{https://ccgm.org/}{Commission for the Geological Map of the World}. |
|
19 |
#' @example inst/examples/ex-science-stratigraphy.R |
|
20 |
#' @author N. Frerebeau |
|
21 |
#' @family themed color schemes |
|
22 |
#' @family qualitative color schemes |
|
23 |
#' @export |
|
24 |
#' @rdname scale_stratigraphy |
|
25 |
scale_colour_stratigraphy <- function(..., lang = "en", aesthetics = "colour") { |
|
26 |
# Get palette |
|
27 | 5x |
color_palette <- color("stratigraphy", names = !is.null(lang), lang = lang) |
28 |
# Build scale |
|
29 | 5x |
ggplot2::scale_color_manual(..., values = color_palette(175), |
30 | 5x |
aesthetics = aesthetics) |
31 |
} |
|
32 | ||
33 |
#' @export |
|
34 |
#' @rdname scale_stratigraphy |
|
35 |
scale_color_stratigraphy <- scale_colour_stratigraphy |
|
36 | ||
37 |
#' @export |
|
38 |
#' @rdname scale_stratigraphy |
|
39 |
scale_fill_stratigraphy <- function(..., lang = "en", aesthetics = "fill") { |
|
40 |
# Get palette |
|
41 | 3x |
color_palette <- color("stratigraphy", names = !is.null(lang), lang = lang) |
42 |
# Build scale |
|
43 | 3x |
ggplot2::scale_fill_manual(..., values = color_palette(175), |
44 | 3x |
aesthetics = aesthetics) |
45 |
} |
|
46 | ||
47 |
#' @export |
|
48 |
#' @rdname scale_stratigraphy |
|
49 |
scale_edge_colour_stratigraphy <- function(..., lang = "en") { |
|
50 |
# Get palette |
|
51 | 5x |
color_palette <- color("stratigraphy", names = !is.null(lang), lang = lang) |
52 |
# Build scale |
|
53 | 5x |
ggraph::scale_edge_colour_manual(..., values = color_palette(175)) |
54 |
} |
|
55 | ||
56 |
#' @export |
|
57 |
#' @rdname scale_stratigraphy |
|
58 |
scale_edge_color_stratigraphy <- scale_edge_colour_stratigraphy |
|
59 | ||
60 |
#' @export |
|
61 |
#' @rdname scale_stratigraphy |
|
62 |
scale_edge_fill_stratigraphy <- function(..., lang = "en") { |
|
63 |
# Get palette |
|
64 | 3x |
color_palette <- color("stratigraphy", names = !is.null(lang), lang = lang) |
65 |
# Build scale |
|
66 | 3x |
ggraph::scale_edge_fill_manual(..., values = color_palette(175)) |
67 |
} |
|
68 | ||
69 |
# Land ========================================================================= |
|
70 |
#' AVHRR Global Land Cover Classification Color Scheme for \pkg{ggplot2} |
|
71 |
#' and \pkg{ggraph} |
|
72 |
#' |
|
73 |
#' Provides the AVHRR Global Land Cover classification as modified by |
|
74 |
#' Paul Tol (colorblind safe). |
|
75 |
#' @param ... Arguments passed on to [ggplot2::discrete_scale()]. |
|
76 |
#' @param lang A [`character`] string specifying the language for the |
|
77 |
#' color names (see details). It must be one of "`en`" (english, the |
|
78 |
#' default), "`fr`" (french) or `NULL`. If not `NULL`, the values will be |
|
79 |
#' matched based on the color names. |
|
80 |
#' @param aesthetics A [`character`] string or vector of character |
|
81 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
82 |
#' @details Values will be matched based on the land classification names. |
|
83 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
84 |
#' @references |
|
85 |
#' Tol, P. (2018). *Colour Schemes.* SRON. Technical Note No. |
|
86 |
#' SRON/EPS/TN/09-002, issue 3.1. |
|
87 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
88 |
#' @example inst/examples/ex-science-land.R |
|
89 |
#' @author N. Frerebeau |
|
90 |
#' @family themed color schemes |
|
91 |
#' @family qualitative color schemes |
|
92 |
#' @export |
|
93 |
#' @rdname scale_land |
|
94 |
scale_colour_land <- function(..., lang = "en", aesthetics = "colour") { |
|
95 |
# Get palette |
|
96 | 5x |
color_palette <- color("land", names = !is.null(lang), lang = lang) |
97 |
# Build scale |
|
98 | 5x |
ggplot2::scale_color_manual(..., values = color_palette(14), |
99 | 5x |
aesthetics = aesthetics) |
100 |
} |
|
101 | ||
102 |
#' @export |
|
103 |
#' @rdname scale_land |
|
104 |
scale_color_land <- scale_colour_land |
|
105 | ||
106 |
#' @export |
|
107 |
#' @rdname scale_land |
|
108 |
scale_fill_land <- function(..., lang = "en", aesthetics = "fill") { |
|
109 |
# Get palette |
|
110 | 3x |
color_palette <- color("land", names = !is.null(lang), lang = lang) |
111 |
# Build scale |
|
112 | 3x |
ggplot2::scale_fill_manual(..., values = color_palette(14), |
113 | 3x |
aesthetics = aesthetics) |
114 |
} |
|
115 | ||
116 |
#' @export |
|
117 |
#' @rdname scale_land |
|
118 |
scale_edge_colour_land <- function(..., lang = "en") { |
|
119 |
# Get palette |
|
120 | 5x |
color_palette <- color("land", names = !is.null(lang), lang = lang) |
121 |
# Build scale |
|
122 | 5x |
ggraph::scale_edge_colour_manual(..., values = color_palette(14)) |
123 |
} |
|
124 | ||
125 |
#' @export |
|
126 |
#' @rdname scale_land |
|
127 |
scale_edge_color_land <- scale_edge_colour_land |
|
128 | ||
129 |
#' @export |
|
130 |
#' @rdname scale_land |
|
131 |
scale_edge_fill_land <- function(..., lang = "en") { |
|
132 |
# Get palette |
|
133 | 3x |
color_palette <- color("land", names = !is.null(lang), lang = lang) |
134 |
# Build scale |
|
135 | 3x |
ggraph::scale_edge_fill_manual(..., values = color_palette(14)) |
136 |
} |
|
137 | ||
138 |
# Soil ========================================================================= |
|
139 |
#' FAO Soil Reference Groups Color Scheme for \pkg{ggplot2} and \pkg{ggraph} |
|
140 |
#' |
|
141 |
#' Provides the FAO Soil Reference Groups color scheme. |
|
142 |
#' @param ... Arguments passed on to [ggplot2::discrete_scale()]. |
|
143 |
#' @param lang A [`character`] string specifying the language for the |
|
144 |
#' color names (see details). It must be one of "`en`" (english, the |
|
145 |
#' default), "`fr`" (french) or `NULL`. If not `NULL`, the values will be |
|
146 |
#' matched based on the color names. |
|
147 |
#' @param aesthetics A [`character`] string or vector of character |
|
148 |
#' strings listing the name(s) of the aesthetic(s) that this scale works with. |
|
149 |
#' @details Values will be matched based on the soil names. |
|
150 |
#' @references |
|
151 |
#' Jones, A., Montanarella, L. & Jones, R. (Ed.) (2005). *Soil atlas of |
|
152 |
#' Europe*. Luxembourg: European Commission, Office for Official Publications |
|
153 |
#' of the European Communities. 128 pp. ISBN: 92-894-8120-X. |
|
154 |
#' @return A [discrete][ggplot2::discrete_scale] scale. |
|
155 |
#' @example inst/examples/ex-science-soil.R |
|
156 |
#' @author N. Frerebeau |
|
157 |
#' @family themed color schemes |
|
158 |
#' @family qualitative color schemes |
|
159 |
#' @export |
|
160 |
#' @rdname scale_soil |
|
161 |
scale_colour_soil <- function(..., lang = "en", aesthetics = "colour") { |
|
162 |
# Get palette |
|
163 | 5x |
color_palette <- color("soil", names = !is.null(lang), lang = lang) |
164 |
# Build scale |
|
165 | 5x |
ggplot2::scale_color_manual(..., values = color_palette(24), |
166 | 5x |
aesthetics = aesthetics) |
167 |
} |
|
168 | ||
169 |
#' @export |
|
170 |
#' @rdname scale_soil |
|
171 |
scale_color_soil <- scale_colour_soil |
|
172 | ||
173 |
#' @export |
|
174 |
#' @rdname scale_soil |
|
175 |
scale_fill_soil <- function(..., lang = "en", aesthetics = "fill") { |
|
176 |
# Get palette |
|
177 | 3x |
color_palette <- color("soil", names = !is.null(lang), lang = lang) |
178 |
# Build scale |
|
179 | 3x |
ggplot2::scale_fill_manual(..., values = color_palette(24), |
180 | 3x |
aesthetics = aesthetics) |
181 |
} |
|
182 | ||
183 |
#' @export |
|
184 |
#' @rdname scale_soil |
|
185 |
scale_edge_colour_soil <- function(..., lang = "en") { |
|
186 |
# Get palette |
|
187 | 5x |
color_palette <- color("soil", names = !is.null(lang), lang = lang) |
188 |
# Build scale |
|
189 | 5x |
ggraph::scale_edge_colour_manual(..., values = color_palette(24)) |
190 |
} |
|
191 | ||
192 |
#' @export |
|
193 |
#' @rdname scale_soil |
|
194 |
scale_edge_color_soil <- scale_edge_colour_soil |
|
195 | ||
196 |
#' @export |
|
197 |
#' @rdname scale_soil |
|
198 |
scale_edge_fill_soil <- function(..., lang = "en") { |
|
199 |
# Get palette |
|
200 | 3x |
color_palette <- color("soil", names = !is.null(lang), lang = lang) |
201 |
# Build scale |
|
202 | 3x |
ggraph::scale_edge_fill_manual(..., values = color_palette(24)) |
203 |
} |
1 |
#' Plot Color Scheme |
|
2 |
#' |
|
3 |
#' Shows colors in a plot. |
|
4 |
#' @param x A [`character`] vector of colors. |
|
5 |
#' @param colours A [`logical`] scalar: should the hexadecimal representation of |
|
6 |
#' the colors be displayed? |
|
7 |
#' @param names A [`logical`] scalar: should the name of the colors be |
|
8 |
#' displayed? |
|
9 |
#' @param size A [`numeric`] value giving the amount by which plotting text |
|
10 |
#' should be magnified relative to the default. Works the same as `cex` |
|
11 |
#' parameter of [graphics::par()]. |
|
12 |
#' @return |
|
13 |
#' `plot_scheme()` is called for its side-effects: it results in a graphic |
|
14 |
#' being displayed (invisibly returns `x`). |
|
15 |
#' @example inst/examples/ex-plot.R |
|
16 |
#' @author N. Frerebeau |
|
17 |
#' @family diagnostic tools |
|
18 |
#' @export |
|
19 |
plot_scheme <- function(x, colours = FALSE, names = FALSE, size = 1) { |
|
20 |
# Validation |
|
21 | 5x |
assert_color(x) |
22 | ||
23 |
# Save and restore graphical parameters |
|
24 | 4x |
old_par <- graphics::par(no.readonly = TRUE) |
25 | 4x |
on.exit(graphics::par(old_par)) |
26 | ||
27 | 4x |
info <- colours && names |
28 | 4x |
missing <- attr(x, "missing") |
29 | 4x |
bad_data <- !is.null(missing) && !is.na(missing) |
30 | 4x |
if (bad_data) x <- c(x, missing) |
31 | ||
32 | 4x |
n <- length(x) # Number of colors |
33 | 4x |
p <- seq(from = 1, by = 0.75, length.out = n) |
34 | 4x |
q <- 1 - 0.43 * rep(c(0, 1), length.out = n) |
35 | ||
36 | 4x |
graphics::par(mar = c(0, 0, 0, 0) + 0.1, xaxs = "i", yaxs = "i") |
37 | 4x |
graphics::plot( |
38 | 4x |
x = NULL, y = NULL, |
39 | 4x |
xlim = c(0.5, max(p) + 0.5 + bad_data / 2), ylim = c(0, 1.5), |
40 | 4x |
xlab = "", ylab = "", axes = FALSE, asp = 1 |
41 |
) |
|
42 | ||
43 | 4x |
for (i in seq_len(n - bad_data)) { |
44 |
#even <- i %% 2 == 0 |
|
45 | 36x |
draw_hexagon(x = p[[i]], y = q[[i]], r = 0.5, border = NULL, fill = x[[i]]) |
46 |
} |
|
47 | 4x |
if (bad_data) { |
48 | 4x |
draw_circle(x = p[[n]] + 0.5, y = q[[n]], r = 0.5, n = 200, |
49 | 4x |
border = NULL, fill = missing) |
50 |
} |
|
51 | 4x |
delta <- ifelse(colours && names && !is.null(names(x)), 0.1, 0) |
52 | 4x |
if (colours) { |
53 | 2x |
if (bad_data) { |
54 | 2x |
graphics::text(x = p[[n]] + 0.5, y = q[[n]], labels = missing, cex = size) |
55 | 2x |
x <- utils::head(x, -1) |
56 | 2x |
p <- utils::head(p, -1) |
57 | 2x |
q <- utils::head(q, -1) |
58 |
} |
|
59 | 2x |
graphics::text(x = p, y = q - delta * info, labels = x, cex = size) |
60 |
} |
|
61 | 4x |
if (names && !is.null(names(x))) { |
62 | 2x |
graphics::text(x = p, y = q + delta * info, labels = names(x), cex = size) |
63 |
} |
|
64 | ||
65 | 4x |
invisible(x) |
66 |
} |
|
67 | ||
68 |
draw_hexagon <- function(x = 0, y = 0, r = 0.5, border = NULL, fill = NA) { |
|
69 | 36x |
vertices <- seq_len(6) |
70 | 36x |
graphics::polygon( |
71 | 36x |
x = x + r * cos(vertices * 2 * pi / 6), |
72 | 36x |
y = y + r * sin(vertices * 2 * pi / 6), |
73 | 36x |
border = border, |
74 | 36x |
col = fill |
75 |
) |
|
76 |
} |
|
77 |
draw_circle <- function(x = 0, y = 0, r = 0.5, n = 200, |
|
78 |
border = NULL, fill = NA) { |
|
79 | 4x |
theta <- seq(0, 2 * pi, length.out = n) |
80 | 4x |
graphics::polygon( |
81 | 4x |
x = r * cos(theta) + x, |
82 | 4x |
y = r * sin(theta) + y, |
83 | 4x |
border = border, |
84 | 4x |
col = fill |
85 |
) |
|
86 |
} |
1 |
#' Color Schemes |
|
2 |
#' |
|
3 |
#' Provides qualitative, diverging and sequential color schemes. |
|
4 |
#' @param palette A [`character`] string giving the name of the scheme to be |
|
5 |
#' used (see [info()]). |
|
6 |
#' @param reverse A [`logical`] scalar: should the resulting vector of colors |
|
7 |
#' should be reversed? |
|
8 |
#' @param names A [`logical`] scalar: should the names of the colors should be |
|
9 |
#' kept in the resulting vector? |
|
10 |
#' @param lang A [`character`] string specifying the language for the color |
|
11 |
#' names. It must be one of "`en`" (English, the default) or "`fr`" (French). |
|
12 |
#' @param force A [`logical`] scalar. If `TRUE`, forces the color scheme to be |
|
13 |
#' interpolated. It should not be used routinely with qualitative color |
|
14 |
#' schemes, as they are designed to be used as is to remain color-blind safe. |
|
15 |
#' @param ... Further arguments passed to |
|
16 |
#' [colorRampPalette][grDevices::colorRamp]. |
|
17 |
#' @return |
|
18 |
#' A [`function`] function with the following attributes, that when called |
|
19 |
#' with a single argument (an [`integer`] specifying the number of colors) |
|
20 |
#' returns a (named) vector of colors. |
|
21 |
#' |
|
22 |
#' \describe{ |
|
23 |
#' \item{palette}{A [`character`] string giving the name of the |
|
24 |
#' color scheme.} |
|
25 |
#' \item{type}{A [`character`] string giving the corresponding |
|
26 |
#' data type. One of "`qualitative`", "`diverging`" or "`sequential`".} |
|
27 |
#' \item{interpolate}{A [`logical`] scalar: can the color palette be |
|
28 |
#' interpolated?} |
|
29 |
#' \item{missing}{A [`character`] string giving the the hexadecimal |
|
30 |
#' representation of the color that should be used for `NA` values.} |
|
31 |
#' \item{max}{An [`integer`] giving the maximum number of color values. |
|
32 |
#' Only relevant for non-interpolated color schemes.} |
|
33 |
#' } |
|
34 |
#' |
|
35 |
#' For color schemes that can be interpolated (diverging and sequential data), |
|
36 |
#' the color range can be limited with an additional argument. `range` allows |
|
37 |
#' to remove a fraction of the color domain (before being interpolated; see |
|
38 |
#' examples). |
|
39 |
#' @references |
|
40 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
41 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
42 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
43 |
#' |
|
44 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
45 |
#' science communication. *Nature Communications*, 11, 5444. |
|
46 |
#' \doi{10.1038/s41467-020-19160-7} |
|
47 |
#' |
|
48 |
#' Jones, A., Montanarella, L. & Jones, R. (Ed.) (2005). *Soil atlas of |
|
49 |
#' Europe*. Luxembourg: European Commission, Office for Official Publications |
|
50 |
#' of the European Communities. 128 pp. ISBN: 92-894-8120-X. |
|
51 |
#' |
|
52 |
#' Okabe, M. & Ito, K. (2008). *Color Universal Design (CUD): How to Make |
|
53 |
#' Figures and Presentations That Are Friendly to Colorblind People*. |
|
54 |
#' URL: \url{https://jfly.uni-koeln.de/color/}. |
|
55 |
#' |
|
56 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
57 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
58 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
59 |
#' |
|
60 |
#' \href{https://ccgm.org/}{Commission for the Geological Map of the World} |
|
61 |
#' @example inst/examples/ex-palettes.R |
|
62 |
#' @author N. Frerebeau |
|
63 |
#' @family color schemes |
|
64 |
#' @keywords color |
|
65 |
#' @export |
|
66 |
colour <- function(palette, reverse = FALSE, names = FALSE, lang = "en", |
|
67 |
force = FALSE, ...) { |
|
68 |
## Validation |
|
69 | 1771x |
palette <- gsub(pattern = "[[:blank:]]", replacement = "", x = palette) |
70 | 1771x |
palette <- match.arg(palette, names(.schemes), several.ok = FALSE) |
71 | 1771x |
lang <- match.arg(lang, c("en", "fr"), several.ok = FALSE) |
72 | ||
73 |
## Get colors |
|
74 | 1771x |
col_palette <- .schemes[[palette]] |
75 | 1771x |
col_colors <- col_palette[["colours"]] |
76 | 1771x |
col_names <- col_palette[["names"]][[lang]] |
77 | 1771x |
col_type <- col_palette[["type"]] |
78 | 1771x |
col_interpolate <- col_palette[["interpolate"]] |
79 | 1771x |
col_missing <- col_palette[["missing"]] |
80 | 1771x |
col_scheme <- col_palette[["scheme"]] |
81 | 1771x |
k <- col_palette[["max"]] |
82 | ||
83 |
## Reverse color order |
|
84 | 52x |
if (reverse) col_colors <- rev(col_colors) |
85 | ||
86 | 1771x |
if (col_interpolate || force) { |
87 | ||
88 |
## For color schemes that can be linearly interpolated |
|
89 | 1253x |
fun <- function(n, range = c(0, 1)) { |
90 | 46x |
if (missing(n)) n <- k |
91 |
# Validate |
|
92 | 897x |
if (any(range > 1) || any(range < 0)) { |
93 | ! |
msg <- tr_("%s values must be in [0,1].") |
94 | ! |
stop(sprintf(msg, sQuote("range")), call. = FALSE) |
95 |
} |
|
96 |
# Remove starting colors |
|
97 | 897x |
col_colors <- utils::tail(col_colors, k * (1 - range[[1]])) |
98 |
# Remove ending colors |
|
99 | 897x |
col_colors <- utils::head(col_colors, k * range[[2]]) |
100 |
# Interpolate |
|
101 | 897x |
col <- grDevices::colorRampPalette(col_colors)(n) |
102 |
# Set attributes |
|
103 | 897x |
col <- structure( |
104 | 897x |
col, |
105 | 897x |
missing = col_missing, |
106 | 897x |
class = c("color_scheme", "color_continuous") |
107 |
) |
|
108 | 897x |
return(col) |
109 |
} |
|
110 | ||
111 |
} else { |
|
112 | ||
113 |
## No interpolation |
|
114 |
## FIXME: add 'range = c(0, 1)' to prevent "multiple local function |
|
115 |
## definitions" note in R CMD check |
|
116 | 518x |
fun <- function(n, range = c(0, 1)) { |
117 | 17x |
if (missing(n)) n <- k |
118 |
# Validate |
|
119 | 295x |
if (n > k) { |
120 | 15x |
msg <- tr_("%s color scheme supports up to %d values.") |
121 | 15x |
stop(sprintf(msg, sQuote(palette), k), call. = FALSE) |
122 |
} |
|
123 |
# Arrange color schemes |
|
124 | 280x |
if (!is.null(col_scheme)) { |
125 | 12x |
m <- col_scheme[[n]] |
126 | 12x |
if (reverse) { |
127 | 1x |
m <- rev(m) |
128 | 1x |
col_colors <- rev(col_colors) |
129 |
} |
|
130 | 12x |
col <- col_colors[m] |
131 | 268x |
} else if (col_type == "qualitative") { |
132 | 268x |
m <- seq_len(n) |
133 | 268x |
col <- col_colors[m] |
134 |
} else { |
|
135 | ! |
m <- seq(from = 1, to = k, length.out = n) |
136 | ! |
col <- col_colors[m] |
137 |
} |
|
138 |
# Keep names? |
|
139 | 196x |
if (names) names(col) <- col_names[m] else col <- unname(col) |
140 |
# Set attributes |
|
141 | 280x |
col <- structure( |
142 | 280x |
col, |
143 | 280x |
missing = col_missing, |
144 | 280x |
class = c("color_scheme", "color_discrete") |
145 |
) |
|
146 | 280x |
return(col) |
147 |
} |
|
148 | ||
149 |
} |
|
150 |
## Set attributes |
|
151 | 1771x |
fun <- structure( |
152 | 1771x |
fun, |
153 | 1771x |
palette = palette, |
154 | 1771x |
type = col_type, |
155 | 1771x |
missing = col_missing, |
156 | 1771x |
interpolate = col_interpolate || force, |
157 | 1771x |
max = as.integer(k) |
158 |
) |
|
159 | 1771x |
return(fun) |
160 |
} |
|
161 | ||
162 |
#' @export |
|
163 |
#' @rdname colour |
|
164 |
color <- colour |
1 |
#' Diagnostic Map |
|
2 |
#' |
|
3 |
#' Produces a diagnostic map for a given color scheme. |
|
4 |
#' @param x A [`character`] vector of colors. |
|
5 |
#' @return |
|
6 |
#' `plot_map()` is called for its side-effects: it results in a graphic |
|
7 |
#' being displayed (invisibly returns `x`). |
|
8 |
#' @example inst/examples/ex-plot.R |
|
9 |
#' @author N. Frerebeau, V. Arel-Bundock |
|
10 |
#' @family diagnostic tools |
|
11 |
#' @export |
|
12 |
plot_map <- function(x) { |
|
13 |
# Validation |
|
14 | 2x |
assert_color(x) |
15 | ||
16 |
# Save and restore graphical parameters |
|
17 | 1x |
old_par <- graphics::par(no.readonly = TRUE) |
18 | 1x |
on.exit(graphics::par(old_par)) |
19 | ||
20 | 1x |
n <- length(x) # Number of colors |
21 | 1x |
q <- floor(100 / (n + 1)) |
22 | ||
23 | 1x |
graphics::par(mar = c(0, 0, 0, 0) + 0.1, xaxs = "i", yaxs = "i") |
24 | 1x |
graphics::plot( |
25 | 1x |
x = NULL, y = NULL, |
26 | 1x |
xlim = c(0, (q * (n + 1) / 2) + 1), ylim = c(0, 10.5), |
27 | 1x |
xlab = "", ylab = "", axes = FALSE, asp = 1 |
28 |
) |
|
29 | ||
30 | 1x |
random_colors <- sample(x, size = 19 * q, replace = TRUE) |
31 | 1x |
draw_mosaic(columns = q, border = "black", fill = random_colors) |
32 | ||
33 | 1x |
for (h in seq_len(n)) { |
34 | 7x |
random_positions <- sample(seq_len(19 * q), size = n, replace = FALSE) |
35 | 7x |
unique_color <- rep(x[[h]], length.out = 19 * q) |
36 | 7x |
unique_color[random_positions] <- x |
37 | ||
38 | 7x |
draw_mosaic(columns = q, border = "black", fill = unique_color, offset = h) |
39 |
} |
|
40 | ||
41 | 1x |
invisible(x) |
42 |
} |
|
43 | ||
44 |
#' Mosaic |
|
45 |
#' |
|
46 |
#' Draws a mosaic of diamonds. |
|
47 |
#' @param rows An [`integer`] giving the number of lines. |
|
48 |
#' @param columns An [`integer`] giving the number of columns. |
|
49 |
#' @param border A [`character`] string giving the color to draw the |
|
50 |
#' border (see \code{\link[graphics]{polygon}}). |
|
51 |
#' @param fill A [`character`] string giving the color for filling |
|
52 |
#' the polygon (see \code{\link[graphics]{polygon}}). |
|
53 |
#' @param offset An [`numeric`] value giving the \code{x} offset from |
|
54 |
#' zero of the mosaic. |
|
55 |
#' @keywords internal |
|
56 |
#' @noRd |
|
57 |
draw_mosaic <- function(rows = 19, columns = 10, border = NULL, fill = NA, |
|
58 |
offset = 0) { |
|
59 | 8x |
fill <- rep(fill, length.out = rows * columns) |
60 | 8x |
k <- 1 |
61 | 8x |
for (i in seq_len(rows)) { # Loop over lines |
62 | 152x |
even <- i %% 2 == 0 |
63 | 152x |
for (j in seq_len(columns)) { # Loop over columns |
64 | 1824x |
graphics::polygon( |
65 | 1824x |
x = c(0, 0.25, 0.5, 0.25) + |
66 | 1824x |
j * 0.5 + 0.25 * even + |
67 | 1824x |
columns * offset / 2, |
68 | 1824x |
y = c(0.5, 1, 0.5, 0) + i * 0.5, |
69 | 1824x |
border = border, |
70 | 1824x |
col = fill[[k]] |
71 |
) |
|
72 | 1824x |
k <- k + 1 |
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 | ||
77 |
# draw_diamond <- function(x = 0, y = 0, width = 0.5, height = 1, |
|
78 |
# border = NULL, fill = NA) { |
|
79 |
# half_width <- width / 2 |
|
80 |
# half_height <- height / 2 |
|
81 |
# graphics::polygon( |
|
82 |
# x = c(x - half_width, x, x + half_width, x), |
|
83 |
# y = c(y, y + half_height, y, y - half_height), |
|
84 |
# border = border, |
|
85 |
# col = fill |
|
86 |
# ) |
|
87 |
# } |
1 |
# HELPERS |
|
2 | ||
3 |
## https://michaelchirico.github.io/potools/articles/developers.html |
|
4 |
tr_ <- function(...) { |
|
5 | 31x |
enc2utf8(gettext(paste0(...), domain = "R-khroma")) |
6 |
} |
|
7 | ||
8 |
`%||%` <- function(x, y) { |
|
9 | 2x |
if (!is.null(x)) x else y |
10 |
} |
|
11 | ||
12 |
assert_package <- function(x) { |
|
13 | 1199x |
if (!requireNamespace(x, quietly = TRUE)) { |
14 | ! |
msg <- tr_("Package %s needed for this function to work. Please install it.") |
15 | ! |
stop(sprintf(msg, sQuote(x)), call. = FALSE) |
16 |
} |
|
17 | 1199x |
invisible(NULL) |
18 |
} |
|
19 | ||
20 |
assert_color <- function(x) { |
|
21 | 11x |
if (!is.atomic(x) || !is.character(x)) { |
22 | 3x |
msg <- tr_("%s must be a character vector of colors.") |
23 | 3x |
stop(sprintf(msg, sQuote("x")), call. = FALSE) |
24 |
} |
|
25 | 8x |
invisible(NULL) |
26 |
} |
1 |
#' Color Difference |
|
2 |
#' |
|
3 |
#' Computes CIELAB distance metric. |
|
4 |
#' @param x A [`character`] vector of colors. |
|
5 |
#' @param metric An [`integer`] value giving the year the metric was |
|
6 |
#' recommended by the CIE. It must be one of "`1976`", "`1994`", or |
|
7 |
#' "`2000`" (default; see [spacesXYZ::DeltaE()]). |
|
8 |
#' @param diag A [`logical`] scalar: should the diagonal of the distance matrix |
|
9 |
#' be printed? |
|
10 |
#' @param upper A [`logical`] scalar: should the upper triangle of the distance |
|
11 |
#' matrix should be printed? |
|
12 |
#' @return A [distance matrix][stats::dist]. |
|
13 |
#' @example inst/examples/ex-compare.R |
|
14 |
#' @author N. Frerebeau |
|
15 |
#' @family diagnostic tools |
|
16 |
#' @export |
|
17 |
compare <- function(x, metric = 2000, diag = FALSE, upper = FALSE) { |
|
18 |
# Validation |
|
19 | 1x |
assert_package("spacesXYZ") |
20 | 1x |
assert_color(x) |
21 | ||
22 |
# Hex to RGB |
|
23 | 1x |
RGB <- t(grDevices::col2rgb(x, alpha = FALSE)) |
24 |
# RGB to Lab |
|
25 | 1x |
Lab <- XYZ2Lab(RGB2XYZ(RGB)) |
26 | ||
27 |
# Color comparisons |
|
28 | 1x |
delta_E <- apply( |
29 | 1x |
X = Lab, |
30 | 1x |
MARGIN = 1, |
31 | 1x |
FUN = spacesXYZ::DeltaE, |
32 | 1x |
Lab2 = Lab, |
33 | 1x |
metric = metric[[1L]] |
34 |
) |
|
35 | ||
36 | 1x |
stats::as.dist(delta_E, diag = diag, upper = upper) |
37 |
} |
1 |
#' Available Schemes |
|
2 |
#' |
|
3 |
#' Returns information about the available schemes. |
|
4 |
#' @return |
|
5 |
#' A [`data.frame`] with the following columns: |
|
6 |
#' \describe{ |
|
7 |
#' \item{`palette`}{Names of palette.} |
|
8 |
#' \item{`type`}{Types of schemes: sequential, diverging or qualitative.} |
|
9 |
#' \item{`max`}{Maximum number of colors that are contained in each |
|
10 |
#' palette. Only relevant for qualitative schemes.} |
|
11 |
#' \item{`missing`}{The hexadecimal color value for mapping missing values.} |
|
12 |
#' } |
|
13 |
#' @example inst/examples/ex-info.R |
|
14 |
#' @author N. Frerebeau |
|
15 |
#' @family color schemes |
|
16 |
#' @export |
|
17 |
info <- function() { |
|
18 | 2x |
meta <- lapply( |
19 | 2x |
X = .schemes, |
20 | 2x |
FUN = function(x) { |
21 | 114x |
list(type = x$type, max = x$max, missing = x$missing) |
22 |
} |
|
23 |
) |
|
24 | 2x |
meta <- do.call(rbind.data.frame, meta) |
25 | 2x |
rownames(meta) <- NULL |
26 | 2x |
colnames(meta) <- c("type", "max", "missing") |
27 | 2x |
meta$palette <- names(.schemes) |
28 | 2x |
meta[, c(4, 1, 2, 3)] |
29 |
} |
|
30 | ||
31 |
# Paul Tol ===================================================================== |
|
32 |
#' Paul Tol's Color Schemes |
|
33 |
#' |
|
34 |
#' @details |
|
35 |
#' The maximum number of supported colors is only relevant for the qualitative |
|
36 |
#' color schemes (divergent and sequential schemes are linearly interpolated). |
|
37 |
#' |
|
38 |
#' \describe{ |
|
39 |
#' \item{Qualitative data}{`bright` (7), `high contrast` (3), `vibrant` (7), |
|
40 |
#' `muted` (9), `medium contrast` (6), `pale` (6), `dark` (6), `light` (9).} |
|
41 |
#' \item{Diverging data}{`sunset` (11), `nightfall` (17), `BuRd` (9), |
|
42 |
#' `PRGn` (9).} |
|
43 |
#' \item{Sequential data}{`YlOrBr` (9), `iridescent` (23), `incandescent` |
|
44 |
#' (11), `discrete rainbow` (23), `smooth rainbow` (34).} |
|
45 |
#' } |
|
46 |
#' @section Qualitative Color Schemes: |
|
47 |
#' The qualitative color schemes are used as given (no interpolation): |
|
48 |
#' colors are picked up to the maximum number of supported values. |
|
49 |
#' |
|
50 |
#' \tabular{ll}{ |
|
51 |
#' **Palette** \tab **Max.** \cr |
|
52 |
#' `bright` \tab 7 \cr |
|
53 |
#' `highcontrast` \tab 3 \cr |
|
54 |
#' `vibrant` \tab 7 \cr |
|
55 |
#' `muted` \tab 9 \cr |
|
56 |
#' `mediumcontrast` \tab 6 \cr |
|
57 |
#' `pale` \tab 6 \cr |
|
58 |
#' `dark` \tab 6 \cr |
|
59 |
#' `light` \tab 9 \cr |
|
60 |
#' } |
|
61 |
#' |
|
62 |
#' According to Paul Tol's technical note, the `bright`, `highcontrast`, |
|
63 |
#' `vibrant` and `muted` color schemes are color-blind safe. The |
|
64 |
#' `mediumcontrast` color scheme is designed for situations needing color |
|
65 |
#' pairs. |
|
66 |
#' |
|
67 |
#' The `light` color scheme is reasonably distinct for both normal or |
|
68 |
#' colorblind vision and is intended to fill labeled cells. |
|
69 |
#' |
|
70 |
#' The `pale` and `dark` schemes are not very distinct in either normal or |
|
71 |
#' colorblind vision and should be used as a text background or to highlight |
|
72 |
#' a cell in a table. |
|
73 |
#' |
|
74 |
#' Refer to the original document for details about the recommended uses (see |
|
75 |
#' references) |
|
76 |
#' @section Diverging Color Schemes: |
|
77 |
#' If more colors than defined are needed from a given scheme, the color |
|
78 |
#' coordinates are linearly interpolated to provide a continuous version of the |
|
79 |
#' scheme. |
|
80 |
#' |
|
81 |
#' \tabular{lll}{ |
|
82 |
#' **Palette** \tab **Max.** \tab **NA value** \cr |
|
83 |
#' `sunset` \tab 11 \tab #FFFFFF \cr |
|
84 |
#' `nightfall` \tab 17 \tab #FFFFFF \cr |
|
85 |
#' `BuRd` \tab 9 \tab #FFEE99 \cr |
|
86 |
#' `PRGn` \tab 9 \tab #FFEE99 \cr |
|
87 |
#' } |
|
88 |
#' |
|
89 |
#' @section Sequential Color Schemes: |
|
90 |
#' If more colors than defined are needed from a given scheme, the color |
|
91 |
#' coordinates are linearly interpolated to provide a continuous version of the |
|
92 |
#' scheme. |
|
93 |
#' |
|
94 |
#' \tabular{lll}{ |
|
95 |
#' **Palette** \tab **Max.** \tab **NA value** \cr |
|
96 |
#' `YlOrBr` \tab 9 \tab #888888 \cr |
|
97 |
#' `iridescent` \tab 23 \tab #999999 \cr |
|
98 |
#' `discreterainbow` \tab 23 \tab #777777 \cr |
|
99 |
#' `smoothrainbow` \tab 34 \tab #666666 \cr |
|
100 |
#' } |
|
101 |
#' @section Rainbow Color Scheme: |
|
102 |
#' As a general rule, ordered data should not be represented using a rainbow |
|
103 |
#' scheme. There are three main arguments against such use (Tol 2018): |
|
104 |
#' \itemize{ |
|
105 |
#' \item{The spectral order of visible light carries no inherent magnitude |
|
106 |
#' message.} |
|
107 |
#' \item{Some bands of almost constant hue with sharp transitions between |
|
108 |
#' them, can be perceived as jumps in the data.} |
|
109 |
#' \item{Color-blind people have difficulty distinguishing some colors of |
|
110 |
#' the rainbow.} |
|
111 |
#' } |
|
112 |
#' If such use cannot be avoided, Paul Tol's technical note provides two color |
|
113 |
#' schemes that are reasonably clear in color-blind vision. To remain |
|
114 |
#' color-blind safe, these two schemes must comply with the following |
|
115 |
#' conditions: |
|
116 |
#' \describe{ |
|
117 |
#' \item{`discreterainbow`}{This scheme must not be interpolated.} |
|
118 |
#' \item{`smoothrainbow`}{This scheme does not have to be used over the full |
|
119 |
#' range.} |
|
120 |
#' } |
|
121 |
#' @references |
|
122 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
123 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
124 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
125 |
#' @keywords internal |
|
126 |
#' @rdname tol |
|
127 |
#' @name tol |
|
128 |
NULL |
|
129 | ||
130 |
# Fabio Crameri ================================================================ |
|
131 |
#' Fabio Crameri's Color Schemes |
|
132 |
#' |
|
133 |
#' @section Diverging Color Schemes: |
|
134 |
#' If more colors than defined are needed from a given scheme, the color |
|
135 |
#' coordinates are linearly interpolated to provide a continuous version of the |
|
136 |
#' scheme. |
|
137 |
#' |
|
138 |
#' \tabular{ll}{ |
|
139 |
#' **Palette** \tab **Max.** \cr |
|
140 |
#' `broc` \tab 256 \cr |
|
141 |
#' `cork` \tab 256 \cr |
|
142 |
#' `vik` \tab 256 \cr |
|
143 |
#' `lisbon` \tab 256 \cr |
|
144 |
#' `tofino` \tab 256 \cr |
|
145 |
#' `berlin` \tab 256 \cr |
|
146 |
#' `roma` \tab 256 \cr |
|
147 |
#' `bam` \tab 256 \cr |
|
148 |
#' `vanimo` \tab 256 \cr |
|
149 |
#' `brocO`* \tab 256 \cr |
|
150 |
#' `corkO`* \tab 256 \cr |
|
151 |
#' `vikO`* \tab 256 \cr |
|
152 |
#' `romaO`* \tab 256 \cr |
|
153 |
#' `bamO`* \tab 256 \cr |
|
154 |
#' } |
|
155 |
#' *: cyclic color schemes. |
|
156 |
#' @section Sequential Color Schemes: |
|
157 |
#' If more colors than defined are needed from a given scheme, the color |
|
158 |
#' coordinates are linearly interpolated to provide a continuous version of the |
|
159 |
#' scheme. |
|
160 |
#' |
|
161 |
#' \tabular{ll}{ |
|
162 |
#' **Palette** \tab **Max.** \cr |
|
163 |
#' `batlow` \tab 256 \cr |
|
164 |
#' `batlowW` \tab 256 \cr |
|
165 |
#' `batlowK` \tab 256 \cr |
|
166 |
#' `devon` \tab 256 \cr |
|
167 |
#' `lajolla` \tab 256 \cr |
|
168 |
#' `bamako` \tab 256 \cr |
|
169 |
#' `davos` \tab 256 \cr |
|
170 |
#' `bilbao` \tab 256 \cr |
|
171 |
#' `nuuk` \tab 256 \cr |
|
172 |
#' `oslo` \tab 256 \cr |
|
173 |
#' `grayC` \tab 256 \cr |
|
174 |
#' `hawaii` \tab 256 \cr |
|
175 |
#' `lapaz` \tab 256 \cr |
|
176 |
#' `tokyo` \tab 256 \cr |
|
177 |
#' `buda` \tab 256 \cr |
|
178 |
#' `acton` \tab 256 \cr |
|
179 |
#' `turku` \tab 256 \cr |
|
180 |
#' `imola` \tab 256 \cr |
|
181 |
#' `oleron`* \tab 256 \cr |
|
182 |
#' `bukavu`* \tab 256 \cr |
|
183 |
#' `fes`* \tab 256 \cr |
|
184 |
#' } |
|
185 |
#' *: multisequential color schemes. |
|
186 |
#' @references |
|
187 |
#' Crameri, F. (2018). Geodynamic diagnostics, scientific visualisation and |
|
188 |
#' StagLab 3.0. *Geosci. Model Dev.*, 11, 2541-2562. |
|
189 |
#' \doi{10.5194/gmd-11-2541-2018} |
|
190 |
#' |
|
191 |
#' Crameri, F., Shephard, G. E. & Heron, P. J. (2020). The misuse of colour in |
|
192 |
#' science communication. *Nature Communications*, 11, 5444. |
|
193 |
#' \doi{10.1038/s41467-020-19160-7} |
|
194 |
#' @source |
|
195 |
#' Crameri, F. (2021). Scientific colour maps. *Zenodo*, v7.0. |
|
196 |
#' \doi{10.5281/zenodo.4491293} |
|
197 |
#' @keywords internal |
|
198 |
#' @rdname crameri |
|
199 |
#' @name crameri |
|
200 |
NULL |
|
201 | ||
202 |
# Science ====================================================================== |
|
203 |
#' Scientific Color Schemes |
|
204 |
#' |
|
205 |
#' @details |
|
206 |
#' The following (qualitative) color schemes are available: |
|
207 |
#' \describe{ |
|
208 |
#' \item{`stratigraphy`}{International Chronostratigraphic Chart (175 colors).} |
|
209 |
#' \item{`land`}{AVHRR Global Land Cover Classification (14 colors).} |
|
210 |
#' \item{`soil`}{FAO Reference Soil Groups (24 colors).} |
|
211 |
#' } |
|
212 |
#' @references |
|
213 |
#' Jones, A., Montanarella, L. & Jones, R. (Ed.) (2005). *Soil atlas of |
|
214 |
#' Europe*. Luxembourg: European Commission, Office for Official Publications |
|
215 |
#' of the European Communities. 128 pp. ISBN: 92-894-8120-X. |
|
216 |
#' |
|
217 |
#' Tol, P. (2021). *Colour Schemes*. SRON. Technical Note No. |
|
218 |
#' SRON/EPS/TN/09-002, issue 3.2. |
|
219 |
#' URL: \url{https://sronpersonalpages.nl/~pault/data/colourschemes.pdf} |
|
220 |
#' |
|
221 |
#' \href{https://ccgm.org/}{Commission for the Geological Map of the World} |
|
222 |
#' @keywords internal |
|
223 |
#' @rdname science |
|
224 |
#' @name science |
|
225 |
NULL |
1 |
#' Diagnostic Map |
|
2 |
#' |
|
3 |
#' Produces a diagnostic map for a given color scheme. |
|
4 |
#' @param x A [`character`] vector of colors. |
|
5 |
#' @param n An [`integer`] specifying the size of the grid (defaults to |
|
6 |
#' \eqn{512}). |
|
7 |
#' @return |
|
8 |
#' `plot_tiles()` is called for its side-effects: it results in a graphic |
|
9 |
#' being displayed (invisibly returns `x`). |
|
10 |
#' @example inst/examples/ex-plot.R |
|
11 |
#' @author N. Frerebeau |
|
12 |
#' @family diagnostic tools |
|
13 |
#' @export |
|
14 |
plot_tiles <- function(x, n = 512) { |
|
15 |
# Validation |
|
16 | 2x |
assert_color(x) |
17 | ||
18 |
# Save and restore graphical parameters |
|
19 | 1x |
old_par <- graphics::par(no.readonly = TRUE) |
20 | 1x |
on.exit(graphics::par(old_par)) |
21 | ||
22 | 1x |
g <- expand.grid( |
23 | 1x |
x = seq_len(n), |
24 | 1x |
y = seq_len(n) |
25 |
) |
|
26 | 1x |
noise <- sin(g$x / 16) + cos(g$y / 16) + |
27 | 1x |
stats::dnorm(sqrt((g$x - 0.75 * n)^2 + (g$y - 0.33 * n)^2) / n * 20) |
28 | 1x |
z <- matrix(data = noise, nrow = n, ncol = n) |
29 | ||
30 | 1x |
graphics::par(mar = c(0, 0, 0, 0) + 0.1, xaxs = "i", yaxs = "i") |
31 | 1x |
graphics::image(x = seq_len(n), y = seq_len(n), z = z, col = x, |
32 | 1x |
axes = FALSE, asp = 1) |
33 | ||
34 | 1x |
invisible(x) |
35 |
} |
1 |
#' Plot Simulated Color Blindness |
|
2 |
#' |
|
3 |
#' Shows colors in a plot with different types of simulated color blindness. |
|
4 |
#' @param x A [`character`] vector of colors. |
|
5 |
#' @return |
|
6 |
#' `plot_scheme_colourblind()` is called for its side-effects: it results in a |
|
7 |
#' graphic being displayed (invisibly returns `x`). |
|
8 |
#' @example inst/examples/ex-change.R |
|
9 |
#' @author N. Frerebeau, V. Arel-Bundock |
|
10 |
#' @family diagnostic tools |
|
11 |
#' @export |
|
12 |
plot_scheme_colourblind <- function(x) { |
|
13 |
# Validation |
|
14 | 1x |
assert_color(x) |
15 | ||
16 | 1x |
n <- length(x) |
17 | 1x |
col <- c(x, anomalize(x, 'deuteranopia'), anomalize(x, 'protanopia'), |
18 | 1x |
anomalize(x, 'tritanopia'), anomalize(x, 'achromatopsia')) |
19 | 1x |
xcoord <- seq(0, 1, length.out = n + 1) |
20 | 1x |
ycoord <- rep(c(.8, .6, .4, .2, 0), each = n) |
21 | 1x |
grid::grid.newpage() |
22 | 1x |
grid::grid.rect( |
23 | 1x |
x = grid::unit(utils::head(xcoord, -1), "npc"), |
24 | 1x |
y = grid::unit(ycoord, "npc"), |
25 | 1x |
width = grid::unit(1 / n, "npc"), |
26 | 1x |
height = grid::unit(0.7 / 5, "npc"), |
27 | 1x |
hjust = 0, |
28 | 1x |
vjust = 0, |
29 | 1x |
gp = grid::gpar(fill = col, col = col) |
30 |
) |
|
31 | 1x |
grid::grid.text( |
32 | 1x |
label = c("Palette", "Deuteranopia", "Protanopia", "Tritanopia", |
33 | 1x |
"Achromatopsia"), |
34 | 1x |
x = grid::unit(0, 'npc'), |
35 | 1x |
y = grid::unit(c(0.97, 0.77, 0.57, 0.37, 0.17), "npc"), |
36 | 1x |
hjust = 0 |
37 |
) |
|
38 | ||
39 | 1x |
invisible(x) |
40 |
} |
|
41 | ||
42 |
#' @rdname plot_scheme_colourblind |
|
43 |
#' @export |
|
44 |
plot_scheme_colorblind <- plot_scheme_colourblind |
1 |
#' Plot Color Scheme |
|
2 |
#' |
|
3 |
#' Quickly displays a color scheme returned by [color()]. |
|
4 |
#' @param x A [`character`] vector of colors. |
|
5 |
#' @param ... Currently not used. |
|
6 |
#' @return |
|
7 |
#' `plot()` is called for its side-effects: it results in a graphic |
|
8 |
#' being displayed (invisibly returns `x`). |
|
9 |
#' @example inst/examples/ex-plot.R |
|
10 |
#' @author N. Frerebeau |
|
11 |
#' @family diagnostic tools |
|
12 |
#' @export |
|
13 |
plot.color_scheme <- function(x, ...) { |
|
14 |
# Save and restore graphical parameters |
|
15 | 1x |
old_par <- graphics::par(no.readonly = TRUE) |
16 | 1x |
on.exit(graphics::par(old_par)) |
17 | ||
18 | 1x |
n <- length(x) |
19 | 1x |
graphics::par(mar = c(0, 0, 0, 0) + 0.1, xaxs = "i", yaxs = "i") |
20 | 1x |
graphics::plot( |
21 | 1x |
x = NULL, y = NULL, |
22 | 1x |
xlim = c(0, n), ylim = c(0, 1), |
23 | 1x |
xlab = "", ylab = "", axes = FALSE |
24 |
) |
|
25 | 1x |
graphics::rect(xleft = seq(0, n - 1), xright = seq(1, n), |
26 | 1x |
ybottom = 0.25, ytop = 0.75, col = x, border = NA) |
27 | ! |
if (n < 25) graphics::abline(v = seq(1, n), col = "#D3D3D3", lwd = 0.25) |
28 | ||
29 | 1x |
invisible(x) |
30 |
} |
1 |
|
|
2 | ||
3 |
#' @export |
|
4 |
print.color_scheme <- function(x, ...) { |
|
5 | ! |
print(unclass(x)) |
6 |
} |