From 6227a46c92b610d282057bc1bf91f1480bbbbf99 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 25 Oct 2024 11:02:33 +0200 Subject: [PATCH] lintr --- DESCRIPTION | 4 +- NAMESPACE | 5 ++ R/scale_color_okabeito.R | 31 ++++++----- R/scale_color_tol.R | 39 +++++-------- man/palette_okabeito.Rd | 4 +- man/palette_tol_discrete.Rd | 33 +++++++++++ man/scale_color_okabeito.Rd | 1 + man/scale_color_tol_discrete.Rd | 98 +++++++++++++++++++++++++++++++++ man/see-package.Rd | 12 ++-- man/tol_colors.Rd | 36 ++++++++++++ 10 files changed, 213 insertions(+), 50 deletions(-) create mode 100644 man/palette_tol_discrete.Rd create mode 100644 man/scale_color_tol_discrete.Rd create mode 100644 man/tol_colors.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 3651c6bf6..80421fe40 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,8 +41,7 @@ Authors@R: person(given = "Matthew", family = "Smith", role = "rev", - email = "M.Smith3@napier.ac.uk", - comment = c(Twitter = "@SmithMatt90")), + email = "M.Smith3@napier.ac.uk"), person(given = "Jakob", family = "Bossek", role = "rev", @@ -121,4 +120,3 @@ Config/testthat/edition: 3 Config/testthat/parallel: true Config/Needs/website: easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true -Remotes: easystats/performance, easystats/parameters diff --git a/NAMESPACE b/NAMESPACE index 7f5dce91b..793ca3c70 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) @@ -198,4 +202,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_okabeito.R b/R/scale_color_okabeito.R index 9cc297e25..51c6b57cc 100644 --- a/R/scale_color_okabeito.R +++ b/R/scale_color_okabeito.R @@ -101,22 +101,23 @@ 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", + orange = "#E69F00", `light blue` = "#56B4E9", - `green` = "#009E73", - `yellow` = "#F0E442", - `blue` = "#0072B2", - `red` = "#D55E00", - `purple` = "#CC79A7", - `grey` = "#999999", - `black` = "#000000", + green = "#009E73", + yellow = "#F0E442", + blue = "#0072B2", + red = "#D55E00", + purple = "#CC79A7", + grey = "#999999", + black = "#000000", `sky blue` = "#56B4E9", `bluish green` = "#009E73", - `vermillion` = "#D55E00", + vermillion = "#D55E00", `reddish purple` = "#CC79A7", `dark yellow` = "#F5C710", - `amber` = "#F5C710" + amber = "#F5C710" ) @@ -171,10 +172,10 @@ okabeito_colors <- function(..., original_names = FALSE, black_first = FALSE, am oi_colors <- okabeito_colors okabeito_palettes <- list( - `full` = okabeito_colors(black_first = FALSE, amber = TRUE), - `black_first` = okabeito_colors(black_first = TRUE, amber = TRUE), - `full_original` = okabeito_colors(black_first = FALSE, amber = FALSE), - `black_original` = okabeito_colors(black_first = TRUE, amber = FALSE) + full = okabeito_colors(black_first = FALSE, amber = TRUE), + black_first = okabeito_colors(black_first = TRUE, amber = TRUE), + full_original = okabeito_colors(black_first = FALSE, amber = FALSE), + black_original = okabeito_colors(black_first = TRUE, amber = FALSE) ) @@ -210,7 +211,7 @@ palette_okabeito <- function(palette = "full_amber", reverse = FALSE, order = 1: stopifnot( "`order` must be a vector of integers." = is.numeric(order), - "All elements of `order` must be greater than 0 and less than 10." = all(order > 0 & order <= 9) + "All elements of `order` must be greater than 0 and less than 10." = order > 0 & order <= 9 ) pal <- pal[order] diff --git a/R/scale_color_tol.R b/R/scale_color_tol.R index 278ae3471..c3fec30b3 100644 --- a/R/scale_color_tol.R +++ b/R/scale_color_tol.R @@ -102,25 +102,25 @@ tol_colors_discrete_list <- list( 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', '6', '9', '10', '12', '14', '15', '16', '17', '18', '20', '22', '24', '26' = "#DC050C", 'grey'), - rainbow23 = c('1', '2', '4', '5', '7', '8', '9', '10', '11', '13', '14', '15', '16', '17', '18', '19', '21', '23', '25', '26' = "#DC050C", '27' = "#A5170E", '28' = "#72190E", '29' = "#42150A", 'grey' = '#777777'), + rainbow14 = c("3", "6", "9", "10", "12", "14", "15", "16", "17", "18", "20", "22", "24", "26" = "#DC050C", "grey"), + rainbow23 = c("1", "2", "4", "5", "7", "8", "9", "10", "11", "13", "14", "15", "16", "17", "18", "19", "21", "23", "25", "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", + woodland = "#558877", "wooded grassland" = "#88BBAA", grassland = "#AADDCC", cropland = "#44AA88", "closed shrubland" = "#DDCC66", "open shrubland" = "#FFDD44", "bare ground" = "#FFEE88", "urband and built up" = "#BB0011" ) ) tol_colors_smooth_list <- list( # Diverging - sunset = c("#"), - BuRd = c(), - PRGn = c(), + sunset = "#", + BuRd = NULL, + PRGn = NULL, # Sequential - YlOrBr = c(), - iridescent = c(), - rainbow = c() + YlOrBr = NULL, + iridescent = NULL, + rainbow = NULL ) @@ -132,9 +132,11 @@ tol_colors_smooth_list <- list( #' #' @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"` +#' - Qualitative: `"bright"`, `"high-contrast"`, `"vibrant"`, `"muted"`,` +#' "medium-contrast"`, `"pale"`, `"dark"`, `"light"`, `"ground_cover"` #' - Diverging: `"sunset"`, `"BuRd"`, `"PRGn"` -#' - Sequential: `"YlOrBr"`, `"iridescent"`, `"rainbow_discrete"`, `"rainbow_smooth"` +#' - Sequential: `"YlOrBr"`, `"iridescent"`, `"rainbow_discrete"`, +#' `"rainbow_smooth"` #' #' @return A character vector with color-codes. #' @@ -167,17 +169,6 @@ tol_colors <- function(..., palette = "bright") { okabeito_colors_list[cols] } -#' @rdname okabeito_colors -#' @export -oi_colors <- okabeito_colors - -okabeito_palettes <- list( - `full` = okabeito_colors(black_first = FALSE, amber = TRUE), - `black_first` = okabeito_colors(black_first = TRUE, amber = TRUE), - `full_original` = okabeito_colors(black_first = FALSE, amber = FALSE), - `black_original` = okabeito_colors(black_first = TRUE, amber = FALSE) -) - #' Paul Tol's color palettes #' @@ -189,7 +180,7 @@ okabeito_palettes <- list( #' - 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). -#' @parem ... For sequential palettes other than `rainbow_discrete`, additional arguments to pass to [`colorRampPalette()`][colorRampPalette]. +#' @param ... For sequential palettes other than `rainbow_discrete`, additional arguments to pass to [`colorRampPalette()`][colorRampPalette]. #' #' @references #' Tol, P. (2021). Colour schemes (SRON/EPS Technical Note No. 09-002; Version 3.2). @@ -214,7 +205,7 @@ palette_tol_discrete <- function(palette = "bright", reverse = FALSE, order = NU stopifnot( "`order` must be a vector of integers." = is.numeric(order), - "All elements of `order` must be greater than 0 and less than 10." = all(order > 0 & order <= 9) + "All elements of `order` must be greater than 0 and less than 10." = order > 0 & order <= 9 ) pal <- pal[order] diff --git a/man/palette_okabeito.Rd b/man/palette_okabeito.Rd index 776dd388c..642b0e6f7 100644 --- a/man/palette_okabeito.Rd +++ b/man/palette_okabeito.Rd @@ -23,11 +23,11 @@ or \code{black_first_original}.} \item{...}{Additional arguments to pass to \code{\link[=colorRampPalette]{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_tol_discrete.Rd b/man/palette_tol_discrete.Rd new file mode 100644 index 000000000..9c6578b54 --- /dev/null +++ b/man/palette_tol_discrete.Rd @@ -0,0 +1,33 @@ +% 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"}, \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[=colorRampPalette]{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_okabeito.Rd b/man/scale_color_okabeito.Rd index a5bcb4e7f..f8f3bb460 100644 --- a/man/scale_color_okabeito.Rd +++ b/man/scale_color_okabeito.Rd @@ -96,6 +96,7 @@ 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[=scale_color_tol]{Paul Tol's palettes} or \link[ggplot2:scale_viridis]{the viridis palettes}. } \examples{ diff --git a/man/scale_color_tol_discrete.Rd b/man/scale_color_tol_discrete.Rd new file mode 100644 index 000000000..f14f485f2 --- /dev/null +++ b/man/scale_color_tol_discrete.Rd @@ -0,0 +1,98 @@ +% 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} +\title{Paul Tol discrete/qualitative color palettes} +\usage{ +scale_color_tol_discrete( + palette = "bright", + reverse = FALSE, + order = NULL, + aesthetics = "color", + ... +) +} +\arguments{ +\item{palette}{Character name of palette. Depending on the color scale, can +be \code{"full"}, \code{"ice"}, \code{"rainbow"}, \code{"complement"}, +\code{"contrast"}, \code{"light"} (for dark themes), \code{"black_first"}, \code{full_original}, +or \code{black_first_original}.} + +\item{reverse}{Boolean indicating whether the palette should be reversed.} + +\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 passed to \code{discrete_scale()} when \code{discrete} +is \code{TRUE} or to \code{scale_color_gradientn()} when \code{discrete} is \code{FALSE}.} +} +\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: bright, high-contrast, vibrant, muted, medium-contrast, pale, dark, light, ground_cover +\item Diverging: sunset, BuRd, PRGn +\item Sequential: YlOrBr, iridescent, rainbow_discrete, 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/see-package.Rd b/man/see-package.Rd index 33bc37094..4e2cea88a 100644 --- a/man/see-package.Rd +++ b/man/see-package.Rd @@ -25,13 +25,13 @@ Useful links: } \author{ -\strong{Maintainer}: Indrajeet Patil \email{patilindrajeet.science@gmail.com} (\href{https://orcid.org/0000-0003-1995-6531}{ORCID}) (@patilindrajeets) +\strong{Maintainer}: Indrajeet Patil \email{patilindrajeet.science@gmail.com} (\href{https://orcid.org/0000-0003-1995-6531}{ORCID}) Authors: \itemize{ - \item Daniel Lüdecke \email{d.luedecke@uke.de} (\href{https://orcid.org/0000-0002-8895-3206}{ORCID}) (@strengejacke) [contributor] - \item Dominique Makowski \email{dom.makowski@gmail.com} (\href{https://orcid.org/0000-0001-5375-9967}{ORCID}) (@Dom_Makowski) [inventor] - \item Mattan S. Ben-Shachar \email{matanshm@post.bgu.ac.il} (\href{https://orcid.org/0000-0002-4287-4801}{ORCID}) (@mattansb) [contributor] + \item Daniel Lüdecke \email{d.luedecke@uke.de} (\href{https://orcid.org/0000-0002-8895-3206}{ORCID}) [contributor] + \item Dominique Makowski \email{dom.makowski@gmail.com} (\href{https://orcid.org/0000-0001-5375-9967}{ORCID}) [inventor] + \item Mattan S. Ben-Shachar \email{matanshm@post.bgu.ac.il} (\href{https://orcid.org/0000-0002-4287-4801}{ORCID}) [contributor] \item Brenton M. Wiernik \email{brenton@wiernik.org} (\href{https://orcid.org/0000-0001-9560-6336}{ORCID}) [contributor] \item Philip Waggoner \email{philip.waggoner@gmail.com} (\href{https://orcid.org/0000-0002-7825-7573}{ORCID}) [contributor] } @@ -39,8 +39,8 @@ Authors: Other contributors: \itemize{ \item Jeffrey R. Stevens \email{jeffrey.r.stevens@gmail.com} (\href{https://orcid.org/0000-0003-2375-1360}{ORCID}) [contributor] - \item Matthew Smith \email{M.Smith3@napier.ac.uk} (@SmithMatt90) [reviewer] - \item Jakob Bossek \email{bossek@wi.uni-muenster.de} (@BossekJakob) [reviewer] + \item Matthew Smith \email{M.Smith3@napier.ac.uk} [reviewer] + \item Jakob Bossek \email{bossek@wi.uni-muenster.de} [reviewer] } } 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") +}