diff --git a/NAMESPACE b/NAMESPACE index baf540162..c03ad46bb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -110,6 +110,7 @@ export(palette_okabeito) export(palette_pizza) export(palette_see) export(palette_social) +export(palette_tol_discrete) export(pizza_colors) export(plots) export(scale_color_bluebrown) @@ -138,6 +139,7 @@ export(scale_color_see_d) export(scale_color_social) export(scale_color_social_c) export(scale_color_social_d) +export(scale_color_tol_discrete) export(scale_colour_bluebrown) export(scale_colour_bluebrown_c) export(scale_colour_bluebrown_d) @@ -164,6 +166,7 @@ export(scale_colour_see_d) export(scale_colour_social) export(scale_colour_social_c) export(scale_colour_social_d) +export(scale_colour_tol_discrete) export(scale_fill_bluebrown) export(scale_fill_bluebrown_c) export(scale_fill_bluebrown_d) @@ -190,6 +193,7 @@ export(scale_fill_see_d) export(scale_fill_social) export(scale_fill_social_c) export(scale_fill_social_d) +export(scale_fill_tol_discrete) export(see_colors) export(social_colors) export(theme_abyss) @@ -199,4 +203,5 @@ export(theme_lucid) export(theme_modern) export(theme_radar) export(theme_radar_dark) +export(tol_colors) import(ggplot2) diff --git a/R/scale_color_flat.R b/R/scale_color_flat.R index b785d473d..b5c125a9e 100644 --- a/R/scale_color_flat.R +++ b/R/scale_color_flat.R @@ -153,6 +153,7 @@ scale_fill_flat_d <- function( ) } + #' @rdname scale_color_flat #' @export scale_fill_flat_c <- function( @@ -271,10 +272,10 @@ flat_palettes <- list( #' which are the two scale useful for discrete or gradient color scales, #' respectively. #' @param reverse Boolean indicating whether the palette should be reversed. -#' @param ... Additional arguments to pass to [`colorRampPalette()`][colorRampPalette]. +#' @param ... Additional arguments to pass to [`grDevices::colorRampPalette()`]. #' #' @details This function is usually not called directly, but from within -#' [`scale_color_flat()`][scale_color_flat]. +#' [`scale_color_flat()`]. #' #' @export palette_flat <- function(palette = "contrast", reverse = FALSE, ...) { diff --git a/R/scale_color_metro.R b/R/scale_color_metro.R index bd27261c0..93a0f2f4f 100644 --- a/R/scale_color_metro.R +++ b/R/scale_color_metro.R @@ -232,7 +232,7 @@ metro_palettes <- list( "red" ), contrast = metro_colors("blue", "green", "amber", "purple", "red"), - light = material_colors( + light = metro_colors( "light blue", "red", "yellow", diff --git a/R/scale_color_okabeito.R b/R/scale_color_okabeito.R index e72db7b3b..5480e4d8b 100644 --- a/R/scale_color_okabeito.R +++ b/R/scale_color_okabeito.R @@ -21,9 +21,10 @@ #' the original yellow color suggested by Okabe and Ito (`"#F0E442"`), use #' palettes `"full_original"` or `"black_first_original"`. #' -#' The Okabe-Ito palette is only available as a discrete palette. For -#' color-accessible continuous variables, consider [the viridis -#' palettes][ggplot2::scale_colour_viridis_d()]. +#' The Okabe-Ito palette is only available as a discrete palette. +#' For color-accessible continuous variables, consider +#' [Paul Tol's palettes][scale_color_tol_discrete()] or +#' [the viridis palettes][ggplot2::scale_colour_viridis_d()]. #' #' @inheritParams palette_okabeito #' @inheritParams scale_color_flat @@ -120,6 +121,7 @@ scale_fill_oi <- scale_fill_okabeito # Palette -------------------------------------------------------------------- # The palette from: https://jfly.uni-koeln.de/color/#pallet +# or grDevices::palette.colors() okabeito_colors_list <- c( orange = "#E69F00", `light blue` = "#56B4E9", @@ -147,11 +149,11 @@ okabeito_colors_list <- c( #' @inheritParams flat_colors #' @param original_names Logical. Should the colors be named using the original #' names used by Okabe and Ito (2008), such as "vermillion" (`TRUE`), or -#' simplified names, such as "red" (`FALSE`, default)? -#' Only used if no colors are specified (to see all available colors). -#' @param black_first Logical. Should black be first (`TRUE`) or last (`FALSE`, default) -#' in the color palette? Only used if no colors are specified (to see all -#' available colors). +#' simplified names, such as "red" (`FALSE`, default)? Only used if no colors +#' are specified (to see all available colors). +#' @param black_first Logical. Should black be first (`TRUE`) or last (`FALSE`, +#' default) in the color palette? Only used if no colors are specified (to see +#' all available colors). #' @param amber If amber color should replace yellow in the palette. #' #' @return A character vector with color-codes. @@ -226,7 +228,7 @@ okabeito_palettes <- list( #' Okabe-Ito color palette #' -#' The palette based proposed by Okabe and Ito (2008). +#' The palette based on Okabe and Ito (2008). #' #' @inheritParams palette_flat #' @param order A vector of numbers from 1 to 9 indicating the order of colors to use @@ -238,7 +240,7 @@ okabeito_palettes <- list( #' https://jfly.uni-koeln.de/color/#pallet (Original work published 2002) #' #' @details This function is usually not called directly, but from within -#' [`scale_color_material()`][scale_color_material]. +#' [`scale_color_okabeito()`][scale_color_okabeito]. #' #' @export palette_okabeito <- function( diff --git a/R/scale_color_pizza.R b/R/scale_color_pizza.R index 7713c3d9a..c244d6cb4 100644 --- a/R/scale_color_pizza.R +++ b/R/scale_color_pizza.R @@ -210,7 +210,7 @@ pizza_palettes <- list( #' @param palette Pizza type. Can be `"margherita"` (default), `"margherita crust"`, #' `"diavola"` or `"diavola crust"`. #' @param reverse Boolean indicating whether the palette should be reversed. -#' @param ... Additional arguments to pass to [`colorRampPalette()`][colorRampPalette]. +#' @param ... Additional arguments to pass to [`grDevices::colorRampPalette()`]. #' #' @details This function is usually not called directly, but from within #' [`scale_color_pizza()`][scale_color_pizza]. diff --git a/R/scale_color_tol.R b/R/scale_color_tol.R new file mode 100644 index 000000000..1b3c3b2a7 --- /dev/null +++ b/R/scale_color_tol.R @@ -0,0 +1,241 @@ +#' Paul Tol discrete/qualitative color palettes +#' +#' Tol (2021) presents a series of palettes built with mathematical principles +#' that are appropriate for diverse types of data. The colors in these schemes +#' are: +#' - Visually distinct for all people, including viewers with color vision +#' deficiencies +#' - Distinct from black and white +#' - Distinct on screen and paper, +#' - Cohesive; that is, they match well together +#' +#' Tol provides palettes appropriate to the 3 main types of data: +#' 1. Qualitative data – nominal or categorical data, where magnitude +#' differences are not relevant. +#' 2. Diverging data – data ordered between two extremes where the midpoint is +#' important. +#' 3. Sequential data – data ordered from low to high. +#' +#' This function provides the qualitative palettes, as well as discrete rainbow +#' sequential palettes. Available palettes for each type of data are: +#' - Qualitative: `bright`, `high-contrast`, `vibrant`, `muted`, +#' `medium-contrast`, `pale`, `dark`, `light`, `ground_cover` +#' - Diverging: `sunset`, `nightfall`, `BuRd`, `PRGn` +#' - Sequential: `YlOrBr`, `iridescent`, `rainbow_discrete`, `rainbow_smooth` +#' +#' +#' +#' +#' +#' ## Colors for missing or invalid data +#' +#' A useful feature of Tol's diverging and sequential palettes is that he +#' provides a recommended color to use for data that fall outside the data range +#' represented by the color scale (e.g., for invalid or missing data). These +#' colors are chosen to be highly distinct from the main color palette. +#' +#' @inheritParams palette_tol_discrete +#' @inheritParams scale_color_flat +#' +#' @references +#' Tol, P. (2021). Colour schemes (SRON/EPS Technical Note No. 09-002; Version 3.2). +#' SRON. https://personal.sron.nl/~pault/data/colourschemes.pdf (Original work published 2009) +#' +#' @examples +#' library(ggplot2) +#' library(see) +#' +#' ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + +#' geom_boxplot() + +#' theme_modern() + +#' scale_fill_okabeito() +#' +#' ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + +#' geom_violin() + +#' theme_modern() + +#' scale_fill_oi(palette = "black_first") +#' +#' # for the original brighter yellow color suggested by Okabe and Ito +#' ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + +#' geom_violin() + +#' theme_modern() + +#' scale_fill_oi(palette = "full") +#' +#' ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + +#' geom_violin() + +#' theme_modern() + +#' scale_fill_oi(order = c(1, 5, 6, 2, 4, 3, 7)) +#' @export +scale_color_tol_discrete <- function(palette = "bright", reverse = FALSE, order = NULL, aesthetics = "color", ...) { + discrete_scale( + aesthetics = aesthetics, + palette = palette_tol_discrete(palette = palette, reverse = reverse, order = order), + ... + ) +} + +# Fill -------------------------------------------------------------------- + +#' @rdname scale_color_tol_discrete +#' @export +scale_fill_tol_discrete <- function(palette = "bright", reverse = FALSE, order = NULL, aesthetics = "fill", ...) { + discrete_scale( + aesthetics = aesthetics, + palette = palette_tol_discrete(palette = palette, reverse = reverse, order = order), + ... + ) +} + +# Aliases ----------------------------------------------------------------- + +#' @rdname scale_color_tol_discrete +#' @export +scale_colour_tol_discrete <- scale_color_tol_discrete + + +# Palette -------------------------------------------------------------------- + +tol_colors_discrete_list <- list( + bright = c(blue = "#4477AA", red = "#EE6677", green = "#228833", yellow = "#CCBB44", cyan = "#66CCEE", purple = "#AA3377", grey = "#BBBBBB"), + `high-contrast` = c(blue = "#004488", yellow = "#DDAA33", red = "#BB5566", black = "#000000", white = "#FFFFFF"), + vibrant = c(orange = "#EE7733", blue = "#0077BB", cyan = "#33BBEE", magenta = "#EE3377", red = "#CC3311", teal = "#009988", grey = "#BBBBBB"), + muted = c(rose = "#CC6677", indigo = "#332288", sand = "#DDCC77", green = "#117733", cyan = "#88CCEE", wine = "#882255", teal = "#44AA99", olive = "#999933", purple = "#AA4499", grey = "#DDDDDD"), + `medium-contrast` = c("light blue" = "#6699CC", "dark blue" = "#004488", "light yellow" = "#EECC66", "dark red" = "#994455", "dark yellow" = "#997700", "light red" = "#EE99AA", black = "#000000", white = "#FFFFFF"), + pale = c(blue = "#BBCCEE", cyan = "#CCEEFF", green = "#CCDDAA", yellow = "#EEEEBB", red = "#FFCCCC", grey = "#DDDDDD"), + dark = c(blue = "#222255", cyan = "#225555", green = "#225522", yellow = "#666633", red = "#663333", grey = "#555555"), + light = c(blue = "#77AADD", orange = "#EE8866", yellow = "#EEDD88", pink = "#FFAABB", cyan = "#99DDFF", mint = "#44BB99", pear = "#BBCC33", olive = "#AAAA00", grey = "#DDDDDD"), + # TODO: Finish rainbow color schemes + rainbow14 = c("3" = "#D1BBD7", "6" = "#AE76A3", "9" = "#882E72", "10" = "#1965B0", "12" = "#5289C7", "14" = "#7BAFDE", "15" = "#4EB265", "16" = "#90C987", "17" = "#CAE0AB", "18" = "#F7F056", "20" = "#F6C141", "22" = "#F1932D", "24" = "#E8601C", "26" = "#DC050C", grey = "#777777"), + rainbow23 = c("1" = "#E8ECFB", "2" = "#D9CCE3", "4" = "#CAACCB", "5" = "#BA8DB4", "7" = "#AA6F9E", "8" = "#994F88", "9" = "#882E72", "10" = "#1965B0", "11" = "#437DBF", "13" = "#6195CF", "14" = "#7BAFDE", "15" = "#4EB265", "16" = "#90C987", "17" = "#CAE0AB", "18" = "#F7F056", "19" = "#F7CB45", "21" = "#F4A736", "23" = "#EE8026", "25" = "#E65518", "26" = "#DC050C", "27" = "#A5170E", "28" = "#72190E", "29" = "#42150A", grey = "#777777"), + rainbow_all = c("1" = "#E8ECFB", "2" = "#D9CCE3", "3" = "#D1BBD7", "4" = "#CAACCB", "5" = "#BA8DB4", "6" = "#AE76A3", "7" = "#AA6F9E", "8" = "#994F88", "9" = "#882E72", "10" = "#1965B0", "11" = "#437DBF", "12" = "#5289C7", "13" = "#6195CF", "14" = "#7BAFDE", "15" = "#4EB265", "16" = "#90C987", "17" = "#CAE0AB", "18" = "#F7F056", "19" = "#F7CB45", "20" = "#F6C141", "21" = "#F4A736", "22" = "#F1932D", "23" = "#EE8026", "24" = "#E8601C", "25" = "#E65518", "26" = "#DC050C", "27" = "#A5170E", "28" = "#72190E", "29" = "#42150A", "grey" = "#777777"), + ground_cover = c( + water = "#5566AA", "evergreen needleleaf forest" = "#117733", "deciduous needleleaf forest" = "#44AA66", + "mixed forest" = "#55AA22", "evergreen broadleaf forest" = "#668822", "deciduous broadleaf forest" = "#88BB55", + woodland = "#558877", "wooded grassland" = "#88BBAA", grassland = "#AADDCC", cropland = "#44AA88", + "closed shrubland" = "#DDCC66", "open shrubland" = "#FFDD44", "bare ground" = "#FFEE88", "urband and built up" = "#BB0011" + ) +) + +#TODO: Add function for rainbow palettes of 1-23 + +# TODO: Add smooth palettes +tol_colors_smooth_list <- list( + # Diverging + sunset = NULL, + nightfall = NULL + BuRd = NULL, + PRGn = NULL, + # Sequential + YlOrBr = NULL, + iridescent = NULL, + rainbow = NULL +) + + +#' Extract Paul Tol colors as hex codes +#' +#' Can be used to get the hex code of specific colors from the Paul Tol palettes. +#' Use `tol_colors()` and specify `palette` to see all available colors. +#' Note that for sequential palettes, only original (non-interpolated) colors are shown. +#' +#' @param ... Character names of colors. +#' @param palette Character name of palette. Can be: +#' - Qualitative: `"bright"`, `"high-contrast"`, `"vibrant"`, `"muted"`,` +#' "medium-contrast"`, `"pale"`, `"dark"`, `"light"`, `"ground_cover"` +#' - Diverging: `"sunset"`, `"nightfall"`, `"BuRd"`, `"PRGn"` +#' - Sequential: `"YlOrBr"`, `"iridescent"`, `"rainbow_discrete"`, +#' `"rainbow_smooth"` +#' +#' @return A character vector with color-codes. +#' +#' @examples +#' tol_colors() +#' +#' tol_colors(c("red", "light blue", "yellow")) +#' +#' tol_colors(palette = "muted") +#' +#' tol_colors(c("red", "light blue", "yellow"), palette = "muted") +#' @export +tol_colors <- function(..., palette = "bright") { + cols <- c(...) + + # TODO: Extract Tol palettes instead of O-I + if (!is.null(cols)) { + return(okabeito_colors_list[cols]) + } + + yellow_col <- if (isTRUE(amber)) "amber" else "yellow" + + if (isTRUE(original_names)) { + cols <- c("orange", "sky blue", "bluish green", yellow_col, "blue", "vermillion", "reddish purple", "grey", "black") + } else { + cols <- c("orange", "light blue", "green", yellow_col, "blue", "red", "purple", "grey", "black") + } + + if (isTRUE(black_first)) cols <- union("black", cols) + + okabeito_colors_list[cols] +} + + +#' Paul Tol's color palettes +#' +#' The palettes proposed by Tol (2021). +#' +#' @param palette Character name of palette. Can be: +#' - Qualitative: `"bright"`, `"high-contrast"`, `"vibrant"`, `"muted"`, +#' `"medium-contrast"`, `"pale"`, `"dark"`, `"light"`, `"ground_cover"` +#' - Diverging: `"sunset"`, `"nightfall",` `"BuRd"`, `"PRGn"` +#' - Sequential: `"YlOrBr"`, `"iridescent"`, `"rainbow_discrete"`, +#' - `"rainbow_smooth"` +#' @param reverse Boolean indicating whether the palette should be reversed. +#' @param order A vector of numbers indicating the order of colors to use +#' (default: `NULL` indicating to use all available colors in order). +#' @param ... For sequential palettes other than `rainbow_discrete`, additional +#' arguments to pass to [`grDevices::colorRampPalette()`]. +#' +#' @references +#' Tol, P. (2021). Colour schemes (SRON/EPS Technical Note No. 09-002; Version 3.2). +#' SRON. https://personal.sron.nl/~pault/data/colourschemes.pdf (Original work published 2009) +#' +#' @details This function is usually not called directly, but from within +#' [`scale_color_tol()`]. +#' +#' @export +palette_tol_discrete <- function(palette = "bright", reverse = FALSE, order = NULL, ...) { + if (!palette %in% names(tol_palettes)) { + msg <- c(paste0( + "Palette name not available. `palette` must be one of ", + datawizard::text_concatenate(names(okabeito_palettes), last = " or ", enclose = "`"), + "." + ), "Using default palette now.") + insight::format_warning(msg) + palette <- "full" + } + + # TODO: Extract Tol palettes instead of O-I + pal <- okabeito_palettes[[palette]] + + stopifnot( + "`order` must be a vector of integers." = is.numeric(order), + "All elements of `order` must be greater than 0 and less than 23." = all(order > 0 & order <= 23) + ) + pal <- pal[order] + + if (reverse) pal <- rev(pal) + + function(n) { + if (n > length(pal)) { + insight::format_warning( + "The number of colors requested `n` is too large.", + paste0("The maximum number of colors is ", length(pal), "."), + paste0("Returning a palette with ", length(pal), " colors.") + ) + n <- length(pal) + } + unname(pal[seq_len(n)]) + } +} diff --git a/inst/WORDLIST b/inst/WORDLIST index d72b33ba7..fbff23c39 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -25,8 +25,12 @@ ORCID Okabe Polychoric Québec +SEM +SRON Shachar Tetrachoric +Tol +Tol's UI Université VIF @@ -87,6 +91,9 @@ qq qqplotr rOpenSci rstanarm +sjPlot +strengejacke +sron subfigures ui unmapped diff --git a/man/okabeito_colors.Rd b/man/okabeito_colors.Rd index 9ed503327..a936dccd7 100644 --- a/man/okabeito_colors.Rd +++ b/man/okabeito_colors.Rd @@ -14,12 +14,12 @@ oi_colors(..., original_names = FALSE, black_first = FALSE, amber = TRUE) \item{original_names}{Logical. Should the colors be named using the original names used by Okabe and Ito (2008), such as "vermillion" (\code{TRUE}), or -simplified names, such as "red" (\code{FALSE}, default)? -Only used if no colors are specified (to see all available colors).} +simplified names, such as "red" (\code{FALSE}, default)? Only used if no colors +are specified (to see all available colors).} -\item{black_first}{Logical. Should black be first (\code{TRUE}) or last (\code{FALSE}, default) -in the color palette? Only used if no colors are specified (to see all -available colors).} +\item{black_first}{Logical. Should black be first (\code{TRUE}) or last (\code{FALSE}, +default) in the color palette? Only used if no colors are specified (to see +all available colors).} \item{amber}{If amber color should replace yellow in the palette.} } diff --git a/man/palette_bluebrown.Rd b/man/palette_bluebrown.Rd index 22067b76f..bc6cd8b11 100644 --- a/man/palette_bluebrown.Rd +++ b/man/palette_bluebrown.Rd @@ -18,7 +18,7 @@ respectively.} \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on blue-brown colors. diff --git a/man/palette_colorhex.Rd b/man/palette_colorhex.Rd index d140b42b9..932b8f912 100644 --- a/man/palette_colorhex.Rd +++ b/man/palette_colorhex.Rd @@ -13,7 +13,7 @@ For example, \code{1014416} for the \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ This function downloads a requested color palette from \url{https://www.color-hex.com/}. diff --git a/man/palette_flat.Rd b/man/palette_flat.Rd index 64bf80722..23e91d793 100644 --- a/man/palette_flat.Rd +++ b/man/palette_flat.Rd @@ -18,7 +18,7 @@ respectively.} \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on \href{https://materialui.co/flatuicolors}{Flat UI}. diff --git a/man/palette_material.Rd b/man/palette_material.Rd index eb3a4f8ae..2e03cafa6 100644 --- a/man/palette_material.Rd +++ b/man/palette_material.Rd @@ -18,7 +18,7 @@ respectively.} \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on \href{https://materialui.co/}{material design colors}. diff --git a/man/palette_metro.Rd b/man/palette_metro.Rd index cf1be7a02..6c7f0c209 100644 --- a/man/palette_metro.Rd +++ b/man/palette_metro.Rd @@ -18,7 +18,7 @@ respectively.} \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on \href{https://materialui.co/metrocolors}{Metro colors}. diff --git a/man/palette_okabeito.Rd b/man/palette_okabeito.Rd index 119ceecb8..e382d11d1 100644 --- a/man/palette_okabeito.Rd +++ b/man/palette_okabeito.Rd @@ -24,14 +24,14 @@ respectively.} \item{order}{A vector of numbers from 1 to 9 indicating the order of colors to use (default: \code{1:9})} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ -The palette based proposed by Okabe and Ito (2008). +The palette based on Okabe and Ito (2008). } \details{ This function is usually not called directly, but from within -\code{\link[=scale_color_material]{scale_color_material()}}. +\code{\link[=scale_color_okabeito]{scale_color_okabeito()}}. } \references{ Okabe, M., & Ito, K. (2008). Color universal design (CUD): diff --git a/man/palette_pizza.Rd b/man/palette_pizza.Rd index 66f26fa06..824d3bfb0 100644 --- a/man/palette_pizza.Rd +++ b/man/palette_pizza.Rd @@ -12,7 +12,7 @@ palette_pizza(palette = "margherita", reverse = FALSE, ...) \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on authentic neapolitan pizzas. diff --git a/man/palette_see.Rd b/man/palette_see.Rd index a39189e64..05fe67bdf 100644 --- a/man/palette_see.Rd +++ b/man/palette_see.Rd @@ -18,7 +18,7 @@ respectively.} \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ See design color palette diff --git a/man/palette_social.Rd b/man/palette_social.Rd index df841ef50..6740ac372 100644 --- a/man/palette_social.Rd +++ b/man/palette_social.Rd @@ -18,7 +18,7 @@ respectively.} \item{reverse}{Boolean indicating whether the palette should be reversed.} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based \href{https://materialui.co/socialcolors}{Social colors}. diff --git a/man/palette_tol_discrete.Rd b/man/palette_tol_discrete.Rd new file mode 100644 index 000000000..9d4eada6e --- /dev/null +++ b/man/palette_tol_discrete.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scale_color_tol.R +\name{palette_tol_discrete} +\alias{palette_tol_discrete} +\title{Paul Tol's color palettes} +\usage{ +palette_tol_discrete(palette = "bright", reverse = FALSE, order = NULL, ...) +} +\arguments{ +\item{palette}{Character name of palette. Can be: +\itemize{ +\item Qualitative: \code{"bright"}, \code{"high-contrast"}, \code{"vibrant"}, \code{"muted"}, +\code{"medium-contrast"}, \code{"pale"}, \code{"dark"}, \code{"light"}, \code{"ground_cover"} +\item Diverging: \code{"sunset"}, \code{"BuRd"}, \code{"PRGn"} +\item Sequential: \code{"YlOrBr"}, \code{"iridescent"}, \code{"rainbow_discrete"}, +\item \code{"rainbow_smooth"} +}} + +\item{reverse}{Boolean indicating whether the palette should be reversed.} + +\item{order}{A vector of numbers indicating the order of colors to use +(default: \code{NULL} indicating to use all available colors in order).} + +\item{...}{For sequential palettes other than \code{rainbow_discrete}, additional +arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} +} +\description{ +The palettes proposed by Tol (2021). +} +\details{ +This function is usually not called directly, but from within +\code{\link[=scale_color_tol]{scale_color_tol()}}. +} +\references{ +Tol, P. (2021). Colour schemes (SRON/EPS Technical Note No. 09-002; Version 3.2). +SRON. https://personal.sron.nl/~pault/data/colourschemes.pdf (Original work published 2009) +} diff --git a/man/scale_color_bluebrown.Rd b/man/scale_color_bluebrown.Rd index 1b3569466..d88f1ed6b 100644 --- a/man/scale_color_bluebrown.Rd +++ b/man/scale_color_bluebrown.Rd @@ -101,7 +101,7 @@ respectively.} \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ A blue-brown color palette. Use \code{scale_color_bluebrown_d()} for diff --git a/man/scale_color_colorhex.Rd b/man/scale_color_colorhex.Rd index 261048c82..b810a24dd 100644 --- a/man/scale_color_colorhex.Rd +++ b/man/scale_color_colorhex.Rd @@ -96,7 +96,7 @@ For example, \code{1014416} for the \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ This function creates color scales based on palettes from \url{https://www.color-hex.com/}. diff --git a/man/scale_color_material.Rd b/man/scale_color_material.Rd index e6a09d35e..ddcce642d 100644 --- a/man/scale_color_material.Rd +++ b/man/scale_color_material.Rd @@ -101,7 +101,7 @@ respectively.} \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on \href{https://materialui.co/}{material design colors}. Use diff --git a/man/scale_color_metro.Rd b/man/scale_color_metro.Rd index 46f292641..40ea6bcfb 100644 --- a/man/scale_color_metro.Rd +++ b/man/scale_color_metro.Rd @@ -101,7 +101,7 @@ respectively.} \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on Metro \href{https://materialui.co/metrocolors}{Metro colors}. diff --git a/man/scale_color_okabeito.Rd b/man/scale_color_okabeito.Rd index 3b16042ec..3625b525b 100644 --- a/man/scale_color_okabeito.Rd +++ b/man/scale_color_okabeito.Rd @@ -75,7 +75,7 @@ respectively.} \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The Okabe-Ito color palette was proposed by Okabe and Ito (2008) as a @@ -99,8 +99,10 @@ The palettes \code{"full"} and \code{"black_first"} use this darker yellow color the original yellow color suggested by Okabe and Ito (\code{"#F0E442"}), use palettes \code{"full_original"} or \code{"black_first_original"}. -The Okabe-Ito palette is only available as a discrete palette. For -color-accessible continuous variables, consider \link[ggplot2:scale_viridis]{the viridis palettes}. +The Okabe-Ito palette is only available as a discrete palette. +For color-accessible continuous variables, consider +\link[=scale_color_tol_discrete]{Paul Tol's palettes} or +\link[ggplot2:scale_viridis]{the viridis palettes}. } \examples{ library(ggplot2) diff --git a/man/scale_color_pizza.Rd b/man/scale_color_pizza.Rd index b88f51be9..3f254ebb7 100644 --- a/man/scale_color_pizza.Rd +++ b/man/scale_color_pizza.Rd @@ -95,7 +95,7 @@ scale_fill_pizza_c( \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based on authentic neapolitan pizzas. diff --git a/man/scale_color_see.Rd b/man/scale_color_see.Rd index 5298d921f..05b13bd34 100644 --- a/man/scale_color_see.Rd +++ b/man/scale_color_see.Rd @@ -101,7 +101,7 @@ respectively.} \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The See color palette. Use \code{scale_color_see_d()} for \emph{discrete} categories diff --git a/man/scale_color_social.Rd b/man/scale_color_social.Rd index fd7134436..a1ea5e9ba 100644 --- a/man/scale_color_social.Rd +++ b/man/scale_color_social.Rd @@ -101,7 +101,7 @@ respectively.} \item{aesthetics}{A vector of names of the aesthetics that this scale should be applied to (e.g., \code{c('color', 'fill')}).} -\item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{colorRampPalette()}}.} +\item{...}{Additional arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} } \description{ The palette based \href{https://materialui.co/socialcolors}{Social colors}. Use diff --git a/man/scale_color_tol_discrete.Rd b/man/scale_color_tol_discrete.Rd new file mode 100644 index 000000000..64ce0c09f --- /dev/null +++ b/man/scale_color_tol_discrete.Rd @@ -0,0 +1,128 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scale_color_tol.R +\name{scale_color_tol_discrete} +\alias{scale_color_tol_discrete} +\alias{scale_fill_tol_discrete} +\alias{scale_colour_tol_discrete} +\title{Paul Tol discrete/qualitative color palettes} +\usage{ +scale_color_tol_discrete( + palette = "bright", + reverse = FALSE, + order = NULL, + aesthetics = "color", + ... +) + +scale_fill_tol_discrete( + palette = "bright", + reverse = FALSE, + order = NULL, + aesthetics = "fill", + ... +) + +scale_colour_tol_discrete( + palette = "bright", + reverse = FALSE, + order = NULL, + aesthetics = "color", + ... +) +} +\arguments{ +\item{palette}{Character name of palette. Can be: +\itemize{ +\item Qualitative: \code{"bright"}, \code{"high-contrast"}, \code{"vibrant"}, \code{"muted"}, +\code{"medium-contrast"}, \code{"pale"}, \code{"dark"}, \code{"light"}, \code{"ground_cover"} +\item Diverging: \code{"sunset"}, \code{"BuRd"}, \code{"PRGn"} +\item Sequential: \code{"YlOrBr"}, \code{"iridescent"}, \code{"rainbow_discrete"}, +\item \code{"rainbow_smooth"} +}} + +\item{reverse}{Boolean indicating whether the palette should be reversed.} + +\item{order}{A vector of numbers indicating the order of colors to use +(default: \code{NULL} indicating to use all available colors in order).} + +\item{aesthetics}{A vector of names of the aesthetics that this scale +should be applied to (e.g., \code{c('color', 'fill')}).} + +\item{...}{For sequential palettes other than \code{rainbow_discrete}, additional +arguments to pass to \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}}.} +} +\description{ +Tol (2021) presents a series of palettes built with mathematical principles +that are appropriate for diverse types of data. The colors in these schemes +are: +\itemize{ +\item Visually distinct for all people, including viewers with color vision +deficiencies +\item Distinct from black and white +\item Distinct on screen and paper, +\item Cohesive; that is, they match well together +} +} +\details{ +Tol provides palettes appropriate to the 3 main types of data: +\enumerate{ +\item Qualitative data – nominal or categorical data, where magnitude +differences are not relevant. +\item Diverging data – data ordered between two extremes where the midpoint is +important. +\item Sequential data – data ordered from low to high. +} + +This function provides the qualitative palettes, as well as discrete rainbow +sequential palettes. Available palettes for each type of data are: +\itemize{ +\item Qualitative: \code{bright}, \code{high-contrast}, \code{vibrant}, \code{muted}, +\code{medium-contrast}, \code{pale}, \code{dark}, \code{light}, \code{ground_cover} +\item Diverging: \code{sunset}, \code{BuRd}, \code{PRGn} +\item Sequential: \code{YlOrBr}, \code{iridescent}, \code{rainbow_discrete}, \code{rainbow_smooth} +}\if{html}{\out{ + +}} +\if{html}{\out{ + +}} + +\subsection{Colors for missing or invalid data}{ + +A useful feature of Tol's diverging and sequential palettes is that he +provides a recommended color to use for data that fall outside the data range +represented by the color scale (e.g., for invalid or missing data). These +colors are chosen to be highly distinct from the main color palette. +} +} +\examples{ +library(ggplot2) +library(see) + +ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + + geom_boxplot() + + theme_modern() + + scale_fill_okabeito() + +ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + + geom_violin() + + theme_modern() + + scale_fill_oi(palette = "black_first") + +# for the original brighter yellow color suggested by Okabe and Ito +ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + + geom_violin() + + theme_modern() + + scale_fill_oi(palette = "full") + +ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + + geom_violin() + + theme_modern() + + scale_fill_oi(order = c(1, 5, 6, 2, 4, 3, 7)) +} +\references{ +Tol, P. (2021). Colour schemes (SRON/EPS Technical Note No. 09-002; Version 3.2). +SRON. https://personal.sron.nl/~pault/data/colourschemes.pdf (Original work published 2009) +} diff --git a/man/tol_colors.Rd b/man/tol_colors.Rd new file mode 100644 index 000000000..a8859a00a --- /dev/null +++ b/man/tol_colors.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scale_color_tol.R +\name{tol_colors} +\alias{tol_colors} +\title{Extract Paul Tol colors as hex codes} +\usage{ +tol_colors(..., palette = "bright") +} +\arguments{ +\item{...}{Character names of colors.} + +\item{palette}{Character name of palette. Can be: +\itemize{ +\item Qualitative: \code{"bright"}, \code{"high-contrast"}, \code{"vibrant"}, \code{"muted"},\code{ "medium-contrast"}, \code{"pale"}, \code{"dark"}, \code{"light"}, \code{"ground_cover"} +\item Diverging: \code{"sunset"}, \code{"BuRd"}, \code{"PRGn"} +\item Sequential: \code{"YlOrBr"}, \code{"iridescent"}, \code{"rainbow_discrete"}, +\code{"rainbow_smooth"} +}} +} +\value{ +A character vector with color-codes. +} +\description{ +Can be used to get the hex code of specific colors from the Paul Tol palettes. +Use \code{tol_colors()} and specify \code{palette} to see all available colors. +Note that for sequential palettes, only original (non-interpolated) colors are shown. +} +\examples{ +tol_colors() + +tol_colors(c("red", "light blue", "yellow")) + +tol_colors(palette = "muted") + +tol_colors(c("red", "light blue", "yellow"), palette = "muted") +}