diff --git a/DESCRIPTION b/DESCRIPTION index 072d295..c41b14a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,6 +16,7 @@ License: GPL (>= 3) Depends: R (>= 4.1.0) Imports: + cli, ggplot2, stringr, systemfonts, diff --git a/NAMESPACE b/NAMESPACE index 96bf230..4d03f12 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ S3method(print,palette) export(acdc_amber) export(acdc_blue) export(acdc_blue_grey) +export(acdc_brewer_palettes) export(acdc_corporate_green) export(acdc_cyan) export(acdc_deep_orange) @@ -46,6 +47,10 @@ export(nhs_purple) export(nhs_warm_yellow) export(nhs_white) export(nhs_yellow) +export(paleta_create_brewer) +export(paleta_create_divergent) +export(paleta_create_qualitative) +export(paleta_create_sequential) export(paleta_fonts) export(set_acdc_font) export(set_nhs_font) @@ -97,6 +102,9 @@ export(wb_light_aqua) export(wb_light_orange) export(wb_palettes) export(wb_white) +importFrom(cli,cli_abort) +importFrom(cli,cli_alert_success) +importFrom(cli,cli_bullets) importFrom(ggplot2,element_blank) importFrom(ggplot2,element_line) importFrom(ggplot2,element_rect) diff --git a/NEWS.md b/NEWS.md index 1dfdc61..3fc4233 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,12 +4,17 @@ * Changed Africa CDC colour palettes based on updated communication style guidelines +* Created sequential and divergent Africa CDC colour palettes + ## General updates -* refresh `pkgdown` website -* refresh GitHub Actions workflows to include Netlify pull request deployment +* refreshed `pkgdown` website +* refreshed GitHub Actions workflows to include Netlify pull request deployment * added appropriate `fig.alt` specifications in all package documentation +## Bug fixes + +* fixed issue with `tint_colour*()` and `shade_colour*()` functions in which they return the opposite percentage tint or shade of a colour or a set of colours # paleta (version 0.0.0.9001) diff --git a/R/paleta.R b/R/paleta.R index e8c1399..6178465 100644 --- a/R/paleta.R +++ b/R/paleta.R @@ -17,5 +17,6 @@ #' @importFrom grid unit #' @importFrom grDevices col2rgb rgb #' @importFrom graphics rect par image text +#' @importFrom cli cli_abort cli_alert_success cli_bullets #' "_PACKAGE" diff --git a/R/paleta_brewer.R b/R/paleta_brewer.R new file mode 100644 index 0000000..7621aed --- /dev/null +++ b/R/paleta_brewer.R @@ -0,0 +1,234 @@ +#' +#' Create new palettes based on organisational palettes +#' +#' These functions apply a similar approach used and demonstrated by +#' [ColorBrewer](https://colorbrewer2.org) and has been patterned after the +#' syntax of the `RColorBrewer` package +#' +#' @param org Name of organisation. Currently supports only *"acdc"* for the +#' Africa CDC colour palettes. +#' @param name Name of the organisational palette to use +#' @param n Number of colours desired/required. Organisational palettes should +#' have at least 3 colours and up to 9 colours maximum. All colour schemes are +#' derived from an organisation's brand/style guidelines. +#' @param type A character value for type of palette to use. Can be either +#' *"sequential"*, *"divergent"*, or *"qualitative"*. +#' +#' @returns A character vector of desired/required colours with length +#' equivalent to `n` +#' +#' @examples +#' paleta_create_sequential(n = 5, org = "acdc", name = "blues") +#' +#' @rdname create_paleta +#' @export +#' + +paleta_create_sequential <- function(n, org, name) { + ## Check if specified palette is found in specified org palette ---- + paleta_check_colour(name = name, org = org) + + ## Check if specified palette is sequential ---- + paleta_check_type(name = name, pal_type = "sequential") + + ## Check if number of colours is compatible with sequential ---- + if (n < 3) { + cli::cli_bullets( + "!" = "Sequential palettes have minimum 3 colours", + "i" = "Returning 3 colours" + ) + + n <- 3 + } + + if (n > 9) { + cli::cli_bullets( + "!" = "Sequential palettes have maximum 9 colours", + "i" = "Returning 9 colours" + ) + + n <- 9 + } + + ## Get base palette ---- + pal <- get(paste0(org, "_brewer_palettes"))[[name]] + + ## Update palette to n ---- + pal <- grDevices::colorRampPalette(pal)(n) + + ## Create palette class ---- + class(pal) <- "palette" + + ## Return palette ---- + pal +} + + +#' +#' @rdname create_paleta +#' @export +#' +paleta_create_divergent <- function(n, name, org) { + ## Check if specified palette is found in specified org palette ---- + paleta_check_colour(name = name, org = org) + + ## Check if specified palette is divergent ---- + paleta_check_type(name = name, pal_type = "divergent") + + ## Check if number of colours is compatible with divergent ---- + if (n < 3) { + cli::cli_bullets( + "!" = "Divergent palettes have minimum 3 colours", + "i" = "Returning 3 colours" + ) + + n <- 3 + } + + if (n > 11) { + cli::cli_bullets( + "!" = "Divergent palettes have maximum 11 colours", + "i" = "Returning 11 colours" + ) + + n <- 11 + } + + ## Get base palette ---- + pal <- get(paste0(org, "_brewer_palettes"))[[name]] + + ## Update palette to n ---- + pal <- grDevices::colorRampPalette(pal)(n) + + ## Create palette class ---- + class(pal) <- "palette" + + ## Return palette ---- + pal +} + +#' +#' @rdname create_paleta +#' @export +#' +paleta_create_qualitative <- function(n, name, org) { + ## Check if specified palette is found in specified org palette ---- + paleta_check_colour(name = name, org = org) + + ## Check if specified palette is divergent ---- + paleta_check_type(name = name, pal_type = "qualitative") + + ## Get base palette ---- + pal <- get(paste0(org, "_brewer_palettes"))[[name]] + + ## Check that n is not more than length(pal) ---- + if (n > length(pal)) { + cli::cli_bullets( + "!" = "{.code n = {n}} is greater than available colours in {name} palette", + "i" = "Returning all colours in {name} colour palette" + ) + + n <- length(pal) + } + + ## Update palette to n ---- + pal <- pal[seq_len(n)] + + ## Create palette class ---- + class(pal) <- "palette" + + ## Return palette ---- + pal +} + + +#' +#' @rdname create_paleta +#' @export +#' +paleta_create_brewer <- function(n, name, org, + type = c("sequential", + "divergent", + "qualitative")) { + ## Determine type of palette ---- + type <- match.arg(type) + + pal <- parse( + text = paste0("paleta_create_", type, "(n = n, name = name, org = org)") + ) |> + eval() + + ## Return palette ---- + pal +} + +#' +#' Palette types +#' +#' @keywords internal +#' + +paleta_brewer_types <- list( + sequential = c( + "blues", "bugn", "bupu", "gnbu", "greens", "greys", "pubu", "pubugn", + "purd", "rdpu", "reds", "ylgn", "ylgnbu", "ylorbr", "ylorrd" + ), + divergent = c( + "brbg", "piylgn", "prgn", "puor", "rdbu", "rdgy","rdylbu", "rdylgn" + ), + qualitative = c( + "pastel1", "pastel2", "pastel3", "dark", "light", "bright" + ) +) + +#' +#' Check if a colour palette name is from a specified organisation +#' +#' @keywords internal +#' + +paleta_check_colour <- function(name, org) { + x <- get(paste0(org, "_brewer_palettes"))[[name]] + + if (is.null(x)) { + cli::cli_abort( + "Colour palette {.val {name}} is not a {org} colour palette" + ) + } else { + cli::cli_alert_success( + "Colour palette {.val {name}} is a {org} colour palette" + ) + } + + ## Return colour palette ---- + x +} + +#' +#' Check if a colour palette is divergent, sequential, or qualitative +#' +#' @keywords internal +#' + +paleta_check_type <- function(name, + pal_type = c("sequential", + "divergent", + "qualitative")) { + pal_type <- match.arg(pal_type) + + type_check <- name %in% paleta_brewer_types[[pal_type]] + + if (!type_check) { + cli::cli_abort( + "{name} is not a {pal_type} colour palette" + ) + + FALSE + } else { + cli::cli_alert_success( + "{name} is a {pal_type} colour palette" + ) + + TRUE + } +} diff --git a/R/theme_acdc.R b/R/theme_acdc.R index b25e74b..a7df77c 100644 --- a/R/theme_acdc.R +++ b/R/theme_acdc.R @@ -9,23 +9,23 @@ #' @rdname acdc_colours #' @export #' -acdc_green <- "#348F41" +acdc_green <- "#348F41" #' @rdname acdc_colours #' @export -acdc_red <- "#9F2241" +acdc_red <- "#9F2241" #' @rdname acdc_colours #' @export -acdc_gold <- "#B4A269" +acdc_gold <- "#B4A269" #' @rdname acdc_colours #' @export -acdc_white <- "#FFFFFF" +acdc_white <- "#FFFFFF" #' @rdname acdc_colours #' @export -acdc_grey <- "#58595B" +acdc_grey <- "#58595B" #' @rdname acdc_colours #' @export @@ -95,17 +95,70 @@ acdc_palettes <- list( acdc_blue, acdc_plum, acdc_blue_grey, acdc_amber, acdc_cyan, acdc_deep_orange, acdc_purple, acdc_lime, acdc_mauve, acdc_pink, acdc_teal ), - acdc_blues = c("#D1DBE8", "#A3B8D2", "#7595BC", "#4772A6", acdc_blue), - acdc_plums = c("#EED0DD", "#DEA2BB", "#CE749A", "#BE4678", acdc_plum), - acdc_blue_greys = c("#DEE5EA", "#BDCBD5", "#9CB1C0", "#7B97AB", acdc_blue_grey), - acdc_ambers = c("#FFF0D1", "#FFE2A3", "#FFD376", "#FFC548", acdc_amber), - acdc_cyans = c("#D1F4F6", "#A4E9ED", "#77DFE4", "#4AD4DB", acdc_cyan), + acdc_blues = c("#D1DBE8", "#A3B8D2", "#7595BC", "#4772A6", acdc_blue), + acdc_plums = c("#EED0DD", "#DEA2BB", "#CE749A", "#BE4678", acdc_plum), + acdc_blue_greys = c("#DEE5EA", "#BDCBD5", "#9CB1C0", "#7B97AB", acdc_blue_grey), + acdc_ambers = c("#FFF0D1", "#FFE2A3", "#FFD376", "#FFC548", acdc_amber), + acdc_cyans = c("#D1F4F6", "#A4E9ED", "#77DFE4", "#4AD4DB", acdc_cyan), acdc_deep_oranges = c("#FFDED6", "#FFBDAE", "#FF9D85", "#FF7C5D", acdc_deep_orange), - acdc_purples = c("#E8DAEA", "#D2B5D6", "#BB91C1", "#A56CAD", acdc_purple), - acdc_limes = c("#F7F9D9", "#F0F3B3", "#E8EE8E", "#E1E868", acdc_lime), - acdc_mauves = c("#D7DEEE", "#AFBDDE", "#879DCD", "#5F7CBD", acdc_mauve), - acdc_pinks = c("#FAD2E3", "#F5A5C8", "#F178AC", "#EC4B91", acdc_pink), - acdc_teals = c("#CCE9E6", "#99D3CD", "#66BEB4", "#33A89B", acdc_teal) + acdc_purples = c("#E8DAEA", "#D2B5D6", "#BB91C1", "#A56CAD", acdc_purple), + acdc_limes = c("#F7F9D9", "#F0F3B3", "#E8EE8E", "#E1E868", acdc_lime), + acdc_mauves = c("#D7DEEE", "#AFBDDE", "#879DCD", "#5F7CBD", acdc_mauve), + acdc_pinks = c("#FAD2E3", "#F5A5C8", "#F178AC", "#EC4B91", acdc_pink), + acdc_teals = c("#CCE9E6", "#99D3CD", "#66BEB4", "#33A89B", acdc_teal) +) + +#' +#' @examples +#' acdc_brewer_palettes +#' +#' @rdname acdc_palette +#' @export +#' +acdc_brewer_palettes <- list( + blues = rev(c(acdc_blue, acdc_blue_grey, acdc_palettes$acdc_blues[2])), + bugn = c(acdc_blue, acdc_lime, acdc_teal), + bupu = c(acdc_blue, acdc_blue_grey, acdc_purple), + gnbu = c(acdc_teal, acdc_lime, acdc_blue), + pubu = c(acdc_purple, acdc_blue_grey, acdc_blue), + pubugn = c(acdc_purple, acdc_blue, acdc_lime), + purd = c(acdc_purple, acdc_plum, acdc_pink), + rdpu = c(acdc_red, acdc_pink, acdc_purple), + ylgn = c(acdc_amber, acdc_teal, acdc_green), + ylgnbu = c(acdc_amber, acdc_lime, acdc_blue), + ylorrd = c(acdc_amber, acdc_deep_orange, acdc_red), + piylgn = c(acdc_pink, acdc_amber, acdc_lime), + prgn = c(acdc_purple, acdc_mauve, acdc_green), + puor = c(acdc_purple, acdc_amber, acdc_deep_orange), + rdbu = c(acdc_red, acdc_plum, acdc_blue), + rdylbu = c(acdc_red, acdc_amber, acdc_blue), + rdylgn = c(acdc_red, acdc_amber, acdc_lime), + pastel1 = c( + acdc_palettes$acdc_blues[3], + acdc_palettes$acdc_plums[3], + acdc_palettes$acdc_blue_grey[3], + acdc_palettes$acdc_amber[3], + acdc_palettes$acdc_cyan[3], + acdc_palettes$acdc_deep_orange[3], + acdc_palettes$acdc_purple[3], + acdc_palettes$acdc_lime[3], + acdc_palettes$acdc_mauve[3], + acdc_palettes$acdc_pink[3], + acdc_palettes$acdc_teal[3] + ), + pastel2 = c( + acdc_palettes$acdc_blues[2], + acdc_palettes$acdc_plums[2], + acdc_palettes$acdc_blue_grey[2], + acdc_palettes$acdc_amber[2], + acdc_palettes$acdc_cyan[2], + acdc_palettes$acdc_deep_orange[2], + acdc_palettes$acdc_purple[2], + acdc_palettes$acdc_lime[2], + acdc_palettes$acdc_mauve[2], + acdc_palettes$acdc_pink[2], + acdc_palettes$acdc_teal[2] + ) ) @@ -201,17 +254,17 @@ set_acdc_font <- function(alt = paleta_fonts$paleta_noto) { #' is `acdc_text`. #' @param subtitle_family Font family to use for the plot subtitle. Default is #' `base_family`. -#' @param subtitle_colour Colour of the subtitle text. Default is `acdc_text`. -#' @param caption_colour Colour of the caption text. Default is `acdc_text`. +#' @param subtitle_colour Colour of the subtitle text. Default is [acdc_text]. +#' @param caption_colour Colour of the caption text. Default is [acdc_text]. #' @param axis_title_colour Colour of the axis title text. Default is #' `acdc_text`. #' @param legend_title_colour Colour of the legend title text. Default is #' `acdc_text`. -#' @param legend_text_colour Colour of the legend text. Default is `acdc_text`. +#' @param legend_text_colour Colour of the legend text. Default is [acdc_text]. #' @param plot_background_fill Fill colour for the plot background. Default is #' NULL. -#' @param grid_col Grid colour. Default to `acdc_gold`. -#' @param axis_col Axis colours. Default to `acdc_gold`. +#' @param grid_col Grid colour. Default to [acdc_gold]. +#' @param axis_col Axis colours. Default to [acdc_gold]. #' @param grid Panel grid. Either `TRUE`, `FALSE`, or a combination of #' `X` (major x grid), `x` (minor x grid), `Y` (major y grid), and/or #' `y` (minor y grid). Default is TRUE. @@ -287,7 +340,7 @@ theme_acdc_light <- function(base_family = set_acdc_font(), theme_acdc_dark <- function(base_family = set_acdc_font(), base_size = 11.5, plot_title_family = base_family, - plot_title_colour = acdc_green, + plot_title_colour = acdc_white, subtitle_family = base_family, subtitle_colour = acdc_white, caption_colour = acdc_white, @@ -319,5 +372,3 @@ theme_acdc_dark <- function(base_family = set_acdc_font(), ticks = ticks ) } - - diff --git a/R/theme_nhs.R b/R/theme_nhs.R index a9ecdf8..2d23aa6 100644 --- a/R/theme_nhs.R +++ b/R/theme_nhs.R @@ -8,87 +8,87 @@ #' @rdname nhs_colours #' @export #' -nhs_blue <- "#005EB8" +nhs_blue <- "#005EB8" #' @rdname nhs_colours #' @export -nhs_white <- "#FFFFFF" +nhs_white <- "#FFFFFF" #' @rdname nhs_colours #' @export -nhs_dark_blue <- "#003087" +nhs_dark_blue <- "#003087" #' @rdname nhs_colours #' @export -nhs_bright_blue <- "#0072CE" +nhs_bright_blue <- "#0072CE" #' @rdname nhs_colours #' @export -nhs_light_blue <- "#41B6E6" +nhs_light_blue <- "#41B6E6" #' @rdname nhs_colours #' @export -nhs_aqua_blue <- "#00A9CE" +nhs_aqua_blue <- "#00A9CE" #' @rdname nhs_colours #' @export -nhs_black <- "#231f20" +nhs_black <- "#231f20" #' @rdname nhs_colours #' @export -nhs_dark_grey <- "#425563" +nhs_dark_grey <- "#425563" #' @rdname nhs_colours #' @export -nhs_mid_grey <- "#768692" +nhs_mid_grey <- "#768692" #' @rdname nhs_colours #' @export -nhs_pale_grey <- "#E8EDEE" +nhs_pale_grey <- "#E8EDEE" #' @rdname nhs_colours #' @export -nhs_dark_green <- "#006747" +nhs_dark_green <- "#006747" #' @rdname nhs_colours #' @export -nhs_green <- "#009639" +nhs_green <- "#009639" #' @rdname nhs_colours #' @export -nhs_light_green <- "#78BE20" +nhs_light_green <- "#78BE20" #' @rdname nhs_colours #' @export -nhs_aqua_green <- "#00A499" +nhs_aqua_green <- "#00A499" #' @rdname nhs_colours #' @export -nhs_purple <- "#330072" +nhs_purple <- "#330072" #' @rdname nhs_colours #' @export -nhs_dark_pink <- "#7C2855" +nhs_dark_pink <- "#7C2855" #' @rdname nhs_colours #' @export -nhs_pink <- "#AE2573" +nhs_pink <- "#AE2573" #' @rdname nhs_colours #' @export -nhs_dark_red <- "#8A1538" +nhs_dark_red <- "#8A1538" #' @rdname nhs_colours #' @export -nhs_orange <- "#ED8B00" +nhs_orange <- "#ED8B00" #' @rdname nhs_colours #' @export -nhs_warm_yellow <- "#FFB81C" +nhs_warm_yellow <- "#FFB81C" #' @rdname nhs_colours #' @export -nhs_yellow <- "#FAE100" +nhs_yellow <- "#FAE100" #' @@ -149,7 +149,7 @@ nhs_fonts <- list( #' Set NHS font to use based on what is available from the system #' #' The function will search the system for availability of any of the NHS -#' fonts in hierarchical order starting with *Andes*, and then *Arial*. If +#' fonts in hierarchical order starting with *Frutiger*, and then *Arial*. If #' none of these are found in the system, the function will return *Noto Sans* #' by default or the user can set which font to use as alternative by specifying #' `alt`. @@ -189,11 +189,11 @@ set_nhs_font <- function(alt = paleta_fonts$paleta_noto) { #' #' A [ggplot2] theme using NHS fonts, colours, and palettes #' -#' These are wrappers for `theme_paleta()` that use colours and fonts from the +#' These are wrappers for [theme_paleta()] that use colours and fonts from the #' NHS visual identity guidelines. #' #' @section Colours: -#' The NHS theme is based on the colours from the `nhs_palettes`. The +#' The NHS theme is based on the colours from the [nhs_palettes]. The #' primary palette consists of two colours: `nhs_palettes$nhs_primary`. The #' secondary palette consists of nineteen colours:. #' @@ -207,7 +207,7 @@ set_nhs_font <- function(alt = paleta_fonts$paleta_noto) { #' [Google Fonts](https://fonts.google.com/). #' #' @param base_family Base font family using NHS fonts. Default is set -#' by what NHS font is available in the system via `set_nhs_font()`. +#' by what NHS font is available in the system via [set_nhs_font()]. #' If none of the NHS fonts are available, the default becomes #' *Noto Sans*. #' @param base_size Base font size. Default is 11.5. @@ -217,14 +217,14 @@ set_nhs_font <- function(alt = paleta_fonts$paleta_noto) { #' is `nhs_blue`. #' @param subtitle_family Font family to use for the plot subtitle. Default is #' `base_family`. -#' @param subtitle_colour Colour of the subtitle text. Default is `nhs_mid_grey`. -#' @param caption_colour Colour of the caption text. Default is `nhs_mid_grey`. +#' @param subtitle_colour Colour of the subtitle text. Default is [nhs_mid_grey]. +#' @param caption_colour Colour of the caption text. Default is [nhs_mid_grey]. #' @param axis_title_colour Colour of the axis title text. Default is #' `nhs_cyan`. #' @param legend_title_colour Colour of the legend title text. Default is NULL. #' @param legend_text_colour Colour of the legend text. Default is NULL. -#' @param grid_col Grid colour. Default to `nhs_pale_grey`. -#' @param axis_col Axis colours. Default to `nhs_pale_grey`. +#' @param grid_col Grid colour. Default to [nhs_pale_grey]. +#' @param axis_col Axis colours. Default to [nhs_pale_grey]. #' @param grid Panel grid. Either `TRUE`, `FALSE`, or a combination of #' `X` (major x grid), `x` (minor x grid), `Y` (major y grid), and/or #' `y` (minor y grid). Default is TRUE. diff --git a/R/theme_paleta.R b/R/theme_paleta.R index c3f5496..0172c6e 100644 --- a/R/theme_paleta.R +++ b/R/theme_paleta.R @@ -67,7 +67,7 @@ set_paleta_font <- function() { #' [Google Fonts](https://fonts.google.com/). #' #' @param base_family Base font family using Africa CDC fonts. Default is set -#' by what Africa CDC font is available in the system via `set_paleta_font()`. +#' by what Africa CDC font is available in the system via [set_paleta_font()]. #' @param base_size Base font size. Default is 11.5. #' @param plot_title_family Font family to use for the plot title. Default is #' `base_family`. @@ -115,7 +115,7 @@ set_paleta_font <- function() { #' @param legend_text_family Font family to use for the legend text. Default #' is `subtitle_family`. #' @param legend_text_colour Colour of the legend text. Default is NULL. -#' @param plot_margin Plot margins (specify with `ggplot2::margin()`). +#' @param plot_margin Plot margins (specify with [ggplot2::margin()]). #' @param plot_background_fill Fill colour for the plot background. Default is #' NULL. #' @param grid_col Grid colour. Default to NULL. diff --git a/R/theme_unicef.R b/R/theme_unicef.R index a54127c..dddbc34 100644 --- a/R/theme_unicef.R +++ b/R/theme_unicef.R @@ -65,12 +65,14 @@ unicef_dark_blue <- "#374EA2" #' @export #' unicef_palettes <- list( - unicef_primary = "#1CABE2", - unicef_secondary = c( + unicef_primary = "#1CABE2", + unicef_secondary = c( "#00833D", "#80BD41", "#FFC20E", "#F26A21", "#E2231A", "#961A49", "#6A1E74", "#D8D1C9", "#777779", "#2D2926", "#374EA2" ), - unicef_brights = c("#00833D", "#80BD41", "#FFC20E", "#F26A21", "#E2231A"), + unicef_brights = c( + "#00833D", "#80BD41", "#FFC20E", "#F26A21", "#E2231A" + ), unicef_neutrals = c( "#961A49", "#6A1E74", "#D8D1C9", "#777779", "#2D2926", "#374EA2" ) @@ -141,11 +143,11 @@ set_unicef_font <- function(alt = paleta_fonts$paleta_noto) { #' #' A [ggplot2] theme using UNICEF fonts, colours, and palettes #' -#' These are wrappers for `theme_paleta()` that use colours and fonts from the +#' These are wrappers for [theme_paleta()] that use colours and fonts from the #' UNICEF visual identity guidelines. #' #' @section Colours: -#' The UNICEF theme is based on the colours from the `unicef_palettes`. The +#' The UNICEF theme is based on the colours from the [unicef_palettes]. The #' primary palette consists of one colour: `unicef_palettes$unicef_primary`. #' The secondary palette consists of eleven colours: #' `unicef_palettes$unicef_secondary`. @@ -160,7 +162,7 @@ set_unicef_font <- function(alt = paleta_fonts$paleta_noto) { #' can be obtained from [Google Fonts](https://fonts.google.com/). #' #' @param base_family Base font family using UNICEF fonts. Default is set -#' by what UNICEF font is available in the system via `set_unicef_font()`. +#' by what UNICEF font is available in the system via [set_unicef_font()]. #' If none of the UNICEF fonts are available, the default becomes #' *Noto Sans*. #' @param base_size Base font size. Default is 11.5. @@ -178,8 +180,8 @@ set_unicef_font <- function(alt = paleta_fonts$paleta_noto) { #' `unicef_cool_grey`. #' @param legend_title_colour Colour of the legend title text. Default is NULL. #' @param legend_text_colour Colour of the legend text. Default is NULL. -#' @param grid_col Grid colour. Default to `unicef_warm_grey`. -#' @param axis_col Axis colours. Default to `unicef_warm_grey`. +#' @param grid_col Grid colour. Default to [unicef_warm_grey]. +#' @param axis_col Axis colours. Default to [unicef_warm_grey]. #' @param grid Panel grid. Either `TRUE`, `FALSE`, or a combination of #' `X` (major x grid), `x` (minor x grid), `Y` (major y grid), and/or #' `y` (minor y grid). Default is TRUE. diff --git a/R/theme_wb.R b/R/theme_wb.R index 42c24d2..2b032d0 100644 --- a/R/theme_wb.R +++ b/R/theme_wb.R @@ -101,20 +101,20 @@ wb_palettes <- list( wb_neutrals = c( "#98252B", "#E16A2D", "#B88C1D", "#614776", "#006068", "#006450" ), - wb_bright_oranges = c("#F05023", "#F3734F", "#F6967B", "#F9B9A7", "#FCDCD3"), - wb_bright_yellows = c("#FDB714", "#FDC543", "#FDD372", "#FEE2A1", "#FEF0D0"), - wb_bright_reds = c("#EB1C2D", "#EF4957", "#F37681", "#F7A4AB", "#FBD1D5"), - wb_light_oranges = c("#F78D28", "#F8A353", "#FABA7E", "#FBD1A9", "#FDE8D4"), - wb_bright_aquas = c("#009CA7", "#33AFB8", "#66C3CA", "#99D7DB", "#CCEBED"), - wb_bright_greens = c("#00AB51", "#33BB73", "#66CC96", "#99DDB9", "#CCEEDC"), - wb_bright_purples = c("#872B90", "#9F55A6", "#B77FBC", "#CFAAD2", "#E7D4E8"), - wb_light_aquas = c("#00A996", "#33BAAB", "#66CBC0", "#99DCD5", "#CCEDEA"), - wb_dark_reds = c("#98252B", "#AC5055", "#C17C7F", "#D5A7AA", "#EAD3D4"), - wb_dark_oranges = c("#E16A2D", "#E78757", "#EDA581", "#F3C3AB", "#F9E1D5"), - wb_browns = c("#B88C1D", "#C6A34A", "#D4BA77", "#E2D1A4", "#F0E8D1"), - wb_dark_purples = c("#614776", "#806B91", "#A090AC", "#BFB5C8", "#DFDAE3"), - wb_dark_aquas = c("#006068", "#337F86", "#669FA4", "#99BFC2", "#CCDFE0"), - wb_dark_greens = c("#006450", "#338373", "#66A296", "#99C1B9", "#CCE0DC") + wb_bright_oranges = rev(c("#F05023", "#F3734F", "#F6967B", "#F9B9A7", "#FCDCD3")), + wb_bright_yellows = rev(c("#FDB714", "#FDC543", "#FDD372", "#FEE2A1", "#FEF0D0")), + wb_bright_reds = rev(c("#EB1C2D", "#EF4957", "#F37681", "#F7A4AB", "#FBD1D5")), + wb_light_oranges = rev(c("#F78D28", "#F8A353", "#FABA7E", "#FBD1A9", "#FDE8D4")), + wb_bright_aquas = rev(c("#009CA7", "#33AFB8", "#66C3CA", "#99D7DB", "#CCEBED")), + wb_bright_greens = rev(c("#00AB51", "#33BB73", "#66CC96", "#99DDB9", "#CCEEDC")), + wb_bright_purples = rev(c("#872B90", "#9F55A6", "#B77FBC", "#CFAAD2", "#E7D4E8")), + wb_light_aquas = rev(c("#00A996", "#33BAAB", "#66CBC0", "#99DCD5", "#CCEDEA")), + wb_dark_reds = rev(c("#98252B", "#AC5055", "#C17C7F", "#D5A7AA", "#EAD3D4")), + wb_dark_oranges = rev(c("#E16A2D", "#E78757", "#EDA581", "#F3C3AB", "#F9E1D5")), + wb_browns = rev(c("#B88C1D", "#C6A34A", "#D4BA77", "#E2D1A4", "#F0E8D1")), + wb_dark_purples = rev(c("#614776", "#806B91", "#A090AC", "#BFB5C8", "#DFDAE3")), + wb_dark_aquas = rev(c("#006068", "#337F86", "#669FA4", "#99BFC2", "#CCDFE0")), + wb_dark_greens = rev(c("#006450", "#338373", "#66A296", "#99C1B9", "#CCE0DC")) ) @@ -176,11 +176,11 @@ set_wb_font <- function(alt = paleta_fonts$paleta_noto) { #' #' A [ggplot2] theme using World Bank fonts, colours, and palettes #' -#' These are wrappers for `theme_paleta()` that use colours and fonts from the +#' These are wrappers for [theme_paleta()] that use colours and fonts from the #' World Bank visual identity guidelines. #' #' @section Colours: -#' The World Bank theme is based on the colours from the `wb_palettes`. The +#' The World Bank theme is based on the colours from the [wb_palettes]. The #' primary palette consists of four colours: `wb_palettes$wb_primary`. The #' secondary palette consists of fourteen colours: `wb_palettes$wb_secondary`. #' @@ -194,7 +194,7 @@ set_wb_font <- function(alt = paleta_fonts$paleta_noto) { #' [Google Fonts](https://fonts.google.com/). #' #' @param base_family Base font family using World Bank fonts. Default is set -#' by what World Bank font is available in the system via `set_wb_font()`. +#' by what World Bank font is available in the system via [set_wb_font()]. #' If none of the World Bank fonts are available, the default becomes #' *Noto Sans*. #' @param base_size Base font size. Default is 11.5. @@ -204,14 +204,14 @@ set_wb_font <- function(alt = paleta_fonts$paleta_noto) { #' is `wb_blue`. #' @param subtitle_family Font family to use for the plot subtitle. Default is #' `base_family`. -#' @param subtitle_colour Colour of the subtitle text. Default is `wb_cyan`. -#' @param caption_colour Colour of the caption text. Default is `wb_cyan`. +#' @param subtitle_colour Colour of the subtitle text. Default is [wb_cyan]. +#' @param caption_colour Colour of the caption text. Default is [wb_cyan]. #' @param axis_title_colour Colour of the axis title text. Default is #' `wb_cyan`. #' @param legend_title_colour Colour of the legend title text. Default is NULL. #' @param legend_text_colour Colour of the legend text. Default is NULL. -#' @param grid_col Grid colour. Default to `wb_cyan`. -#' @param axis_col Axis colours. Default to `wb_cyan`. +#' @param grid_col Grid colour. Default to [wb_cyan]. +#' @param axis_col Axis colours. Default to [wb_cyan]. #' @param grid Panel grid. Either `TRUE`, `FALSE`, or a combination of #' `X` (major x grid), `x` (minor x grid), `Y` (major y grid), and/or #' `y` (minor y grid). Default is TRUE. diff --git a/R/utils.R b/R/utils.R index 3b11e52..c8679e7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -143,7 +143,7 @@ tint_colour <- function(hex, p) { col_rgb <- grDevices::col2rgb(col = hex) (255 - col_rgb) |> - (\(x) x * p)() |> + (\(x) x * (1 - p))() |> (\(x) col_rgb + x)() |> (\(x) grDevices::rgb(x[1], x[2], x[3], maxColorValue = 255))() } @@ -204,7 +204,7 @@ tint_colours <- function(hex, p, label = FALSE) { shade_colour <- function(hex, p) { col_rgb <- grDevices::col2rgb(col = hex) - (col_rgb * p) |> + (col_rgb * (1 - p)) |> (\(x) col_rgb - x)() |> round() |> (\(x) grDevices::rgb(x[1], x[2], x[3], maxColorValue = 255))() @@ -242,4 +242,3 @@ shade_colours <- function(hex, p, label = FALSE) { pal } - diff --git a/inst/WORDLIST b/inst/WORDLIST index c2b89fa..e50c736 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,9 +1,8 @@ -Acumin Aleo CMD -Calibri CodeFactor Codecov +ColorBrewer Frutiger IBRD ICSID @@ -19,12 +18,12 @@ Rudis Univers WBG WIP +acdc bl cmyk computing's ernest guevarra -heirarchical hrbrthemes io organisations’ diff --git a/man/acdc_palette.Rd b/man/acdc_palette.Rd index 51c364d..5b66308 100644 --- a/man/acdc_palette.Rd +++ b/man/acdc_palette.Rd @@ -3,12 +3,17 @@ \docType{data} \name{acdc_palettes} \alias{acdc_palettes} +\alias{acdc_brewer_palettes} \title{Africa CDC palettes} \format{ An object of class \code{list} of length 13. + +An object of class \code{list} of length 19. } \usage{ acdc_palettes + +acdc_brewer_palettes } \description{ Africa CDC palettes @@ -16,5 +21,7 @@ Africa CDC palettes \examples{ acdc_palettes +acdc_brewer_palettes + } \keyword{datasets} diff --git a/man/create_paleta.Rd b/man/create_paleta.Rd new file mode 100644 index 0000000..93592a5 --- /dev/null +++ b/man/create_paleta.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/paleta_brewer.R +\name{paleta_create_sequential} +\alias{paleta_create_sequential} +\alias{paleta_create_divergent} +\alias{paleta_create_qualitative} +\alias{paleta_create_brewer} +\title{Create new palettes based on organisational palettes} +\usage{ +paleta_create_sequential(n, org, name) + +paleta_create_divergent(n, name, org) + +paleta_create_qualitative(n, name, org) + +paleta_create_brewer( + n, + name, + org, + type = c("sequential", "divergent", "qualitative") +) +} +\arguments{ +\item{n}{Number of colours desired/required. Organisational palettes should +have at least 3 colours and up to 9 colours maximum. All colour schemes are +derived from an organisation's brand/style guidelines.} + +\item{org}{Name of organisation. Currently supports only \emph{"acdc"} for the +Africa CDC colour palettes.} + +\item{name}{Name of the organisational palette to use} + +\item{type}{A character value for type of palette to use. Can be either +\emph{"sequential"}, \emph{"divergent"}, or \emph{"qualitative"}.} +} +\value{ +A character vector of desired/required colours with length +equivalent to \code{n} +} +\description{ +These functions apply a similar approach used and demonstrated by +\href{https://colorbrewer2.org}{ColorBrewer} and has been patterned after the +syntax of the \code{RColorBrewer} package +} +\examples{ +paleta_create_sequential(n = 5, org = "acdc", name = "blues") + +} diff --git a/man/nhs_font.Rd b/man/nhs_font.Rd index 99a88e9..9a59c89 100644 --- a/man/nhs_font.Rd +++ b/man/nhs_font.Rd @@ -22,7 +22,7 @@ A character value for font family to use as NHS font. } \description{ The function will search the system for availability of any of the NHS -fonts in hierarchical order starting with \emph{Andes}, and then \emph{Arial}. If +fonts in hierarchical order starting with \emph{Frutiger}, and then \emph{Arial}. If none of these are found in the system, the function will return \emph{Noto Sans} by default or the user can set which font to use as alternative by specifying \code{alt}. diff --git a/man/paleta_brewer_types.Rd b/man/paleta_brewer_types.Rd new file mode 100644 index 0000000..d07d86c --- /dev/null +++ b/man/paleta_brewer_types.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/paleta_brewer.R +\docType{data} +\name{paleta_brewer_types} +\alias{paleta_brewer_types} +\title{Palette types} +\format{ +An object of class \code{list} of length 3. +} +\usage{ +paleta_brewer_types +} +\description{ +Palette types +} +\keyword{internal} diff --git a/man/paleta_check_colour.Rd b/man/paleta_check_colour.Rd new file mode 100644 index 0000000..76947ec --- /dev/null +++ b/man/paleta_check_colour.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/paleta_brewer.R +\name{paleta_check_colour} +\alias{paleta_check_colour} +\title{Check if a colour palette name is from a specified organisation} +\usage{ +paleta_check_colour(name, org) +} +\description{ +Check if a colour palette name is from a specified organisation +} +\keyword{internal} diff --git a/man/paleta_check_type.Rd b/man/paleta_check_type.Rd new file mode 100644 index 0000000..fbdd63d --- /dev/null +++ b/man/paleta_check_type.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/paleta_brewer.R +\name{paleta_check_type} +\alias{paleta_check_type} +\title{Check if a colour palette is divergent, sequential, or qualitative} +\usage{ +paleta_check_type(name, pal_type = c("sequential", "divergent", "qualitative")) +} +\description{ +Check if a colour palette is divergent, sequential, or qualitative +} +\keyword{internal} diff --git a/man/theme_acdc.Rd b/man/theme_acdc.Rd index 9b329c5..6366255 100644 --- a/man/theme_acdc.Rd +++ b/man/theme_acdc.Rd @@ -27,7 +27,7 @@ theme_acdc_dark( base_family = set_acdc_font(), base_size = 11.5, plot_title_family = base_family, - plot_title_colour = acdc_green, + plot_title_colour = acdc_white, subtitle_family = base_family, subtitle_colour = acdc_white, caption_colour = acdc_white, @@ -59,9 +59,9 @@ is \code{acdc_text}.} \item{subtitle_family}{Font family to use for the plot subtitle. Default is \code{base_family}.} -\item{subtitle_colour}{Colour of the subtitle text. Default is \code{acdc_text}.} +\item{subtitle_colour}{Colour of the subtitle text. Default is \link{acdc_text}.} -\item{caption_colour}{Colour of the caption text. Default is \code{acdc_text}.} +\item{caption_colour}{Colour of the caption text. Default is \link{acdc_text}.} \item{axis_title_colour}{Colour of the axis title text. Default is \code{acdc_text}.} @@ -69,15 +69,15 @@ is \code{acdc_text}.} \item{legend_title_colour}{Colour of the legend title text. Default is \code{acdc_text}.} -\item{legend_text_colour}{Colour of the legend text. Default is \code{acdc_text}.} +\item{legend_text_colour}{Colour of the legend text. Default is \link{acdc_text}.} -\item{grid_col}{Grid colour. Default to \code{acdc_gold}.} +\item{grid_col}{Grid colour. Default to \link{acdc_gold}.} \item{grid}{Panel grid. Either \code{TRUE}, \code{FALSE}, or a combination of \code{X} (major x grid), \code{x} (minor x grid), \code{Y} (major y grid), and/or \code{y} (minor y grid). Default is TRUE.} -\item{axis_col}{Axis colours. Default to \code{acdc_gold}.} +\item{axis_col}{Axis colours. Default to \link{acdc_gold}.} \item{axis}{Add x or y axes? \code{TRUE}, \code{FALSE}, "\code{xy}". Default is FALSE.} diff --git a/man/theme_nhs.Rd b/man/theme_nhs.Rd index 52d850e..636948d 100644 --- a/man/theme_nhs.Rd +++ b/man/theme_nhs.Rd @@ -24,7 +24,7 @@ theme_nhs( } \arguments{ \item{base_family}{Base font family using NHS fonts. Default is set -by what NHS font is available in the system via \code{set_nhs_font()}. +by what NHS font is available in the system via \code{\link[=set_nhs_font]{set_nhs_font()}}. If none of the NHS fonts are available, the default becomes \emph{Noto Sans}.} @@ -39,9 +39,9 @@ is \code{nhs_blue}.} \item{subtitle_family}{Font family to use for the plot subtitle. Default is \code{base_family}.} -\item{subtitle_colour}{Colour of the subtitle text. Default is \code{nhs_mid_grey}.} +\item{subtitle_colour}{Colour of the subtitle text. Default is \link{nhs_mid_grey}.} -\item{caption_colour}{Colour of the caption text. Default is \code{nhs_mid_grey}.} +\item{caption_colour}{Colour of the caption text. Default is \link{nhs_mid_grey}.} \item{axis_title_colour}{Colour of the axis title text. Default is \code{nhs_cyan}.} @@ -50,13 +50,13 @@ is \code{nhs_blue}.} \item{legend_text_colour}{Colour of the legend text. Default is NULL.} -\item{grid_col}{Grid colour. Default to \code{nhs_pale_grey}.} +\item{grid_col}{Grid colour. Default to \link{nhs_pale_grey}.} \item{grid}{Panel grid. Either \code{TRUE}, \code{FALSE}, or a combination of \code{X} (major x grid), \code{x} (minor x grid), \code{Y} (major y grid), and/or \code{y} (minor y grid). Default is TRUE.} -\item{axis_col}{Axis colours. Default to \code{nhs_pale_grey}.} +\item{axis_col}{Axis colours. Default to \link{nhs_pale_grey}.} \item{axis}{Add x or y axes? \code{TRUE}, \code{FALSE}, "\code{xy}". Default is FALSE.} @@ -66,12 +66,12 @@ is \code{nhs_blue}.} A \link{ggplot2} theme. } \description{ -These are wrappers for \code{theme_paleta()} that use colours and fonts from the +These are wrappers for \code{\link[=theme_paleta]{theme_paleta()}} that use colours and fonts from the NHS visual identity guidelines. } \section{Colours}{ -The NHS theme is based on the colours from the \code{nhs_palettes}. The +The NHS theme is based on the colours from the \link{nhs_palettes}. The primary palette consists of two colours: \code{nhs_palettes$nhs_primary}. The secondary palette consists of nineteen colours:. } diff --git a/man/theme_paleta.Rd b/man/theme_paleta.Rd index ec77cbe..3f29e43 100644 --- a/man/theme_paleta.Rd +++ b/man/theme_paleta.Rd @@ -46,7 +46,7 @@ theme_paleta( } \arguments{ \item{base_family}{Base font family using Africa CDC fonts. Default is set -by what Africa CDC font is available in the system via \code{set_paleta_font()}.} +by what Africa CDC font is available in the system via \code{\link[=set_paleta_font]{set_paleta_font()}}.} \item{base_size}{Base font size. Default is 11.5.} @@ -125,7 +125,7 @@ is \code{subtitle_family}.} \item{legend_text_colour}{Colour of the legend text. Default is NULL.} -\item{plot_margin}{Plot margins (specify with \code{ggplot2::margin()}).} +\item{plot_margin}{Plot margins (specify with \code{\link[ggplot2:element]{ggplot2::margin()}}).} \item{plot_background_fill}{Fill colour for the plot background. Default is NULL.} diff --git a/man/theme_unicef.Rd b/man/theme_unicef.Rd index dfee9f8..5e4de96 100644 --- a/man/theme_unicef.Rd +++ b/man/theme_unicef.Rd @@ -24,7 +24,7 @@ theme_unicef( } \arguments{ \item{base_family}{Base font family using UNICEF fonts. Default is set -by what UNICEF font is available in the system via \code{set_unicef_font()}. +by what UNICEF font is available in the system via \code{\link[=set_unicef_font]{set_unicef_font()}}. If none of the UNICEF fonts are available, the default becomes \emph{Noto Sans}.} @@ -52,13 +52,13 @@ is \code{unicef_black}.} \item{legend_text_colour}{Colour of the legend text. Default is NULL.} -\item{grid_col}{Grid colour. Default to \code{unicef_warm_grey}.} +\item{grid_col}{Grid colour. Default to \link{unicef_warm_grey}.} \item{grid}{Panel grid. Either \code{TRUE}, \code{FALSE}, or a combination of \code{X} (major x grid), \code{x} (minor x grid), \code{Y} (major y grid), and/or \code{y} (minor y grid). Default is TRUE.} -\item{axis_col}{Axis colours. Default to \code{unicef_warm_grey}.} +\item{axis_col}{Axis colours. Default to \link{unicef_warm_grey}.} \item{axis}{Add x or y axes? \code{TRUE}, \code{FALSE}, "\code{xy}". Default is FALSE.} @@ -68,12 +68,12 @@ is \code{unicef_black}.} A \link{ggplot2} theme. } \description{ -These are wrappers for \code{theme_paleta()} that use colours and fonts from the +These are wrappers for \code{\link[=theme_paleta]{theme_paleta()}} that use colours and fonts from the UNICEF visual identity guidelines. } \section{Colours}{ -The UNICEF theme is based on the colours from the \code{unicef_palettes}. The +The UNICEF theme is based on the colours from the \link{unicef_palettes}. The primary palette consists of one colour: \code{unicef_palettes$unicef_primary}. The secondary palette consists of eleven colours: \code{unicef_palettes$unicef_secondary}. diff --git a/man/theme_wb.Rd b/man/theme_wb.Rd index 61665be..7e38a27 100644 --- a/man/theme_wb.Rd +++ b/man/theme_wb.Rd @@ -24,7 +24,7 @@ theme_wb( } \arguments{ \item{base_family}{Base font family using World Bank fonts. Default is set -by what World Bank font is available in the system via \code{set_wb_font()}. +by what World Bank font is available in the system via \code{\link[=set_wb_font]{set_wb_font()}}. If none of the World Bank fonts are available, the default becomes \emph{Noto Sans}.} @@ -39,9 +39,9 @@ is \code{wb_blue}.} \item{subtitle_family}{Font family to use for the plot subtitle. Default is \code{base_family}.} -\item{subtitle_colour}{Colour of the subtitle text. Default is \code{wb_cyan}.} +\item{subtitle_colour}{Colour of the subtitle text. Default is \link{wb_cyan}.} -\item{caption_colour}{Colour of the caption text. Default is \code{wb_cyan}.} +\item{caption_colour}{Colour of the caption text. Default is \link{wb_cyan}.} \item{axis_title_colour}{Colour of the axis title text. Default is \code{wb_cyan}.} @@ -50,13 +50,13 @@ is \code{wb_blue}.} \item{legend_text_colour}{Colour of the legend text. Default is NULL.} -\item{grid_col}{Grid colour. Default to \code{wb_cyan}.} +\item{grid_col}{Grid colour. Default to \link{wb_cyan}.} \item{grid}{Panel grid. Either \code{TRUE}, \code{FALSE}, or a combination of \code{X} (major x grid), \code{x} (minor x grid), \code{Y} (major y grid), and/or \code{y} (minor y grid). Default is TRUE.} -\item{axis_col}{Axis colours. Default to \code{wb_cyan}.} +\item{axis_col}{Axis colours. Default to \link{wb_cyan}.} \item{axis}{Add x or y axes? \code{TRUE}, \code{FALSE}, "\code{xy}". Default is FALSE.} @@ -66,12 +66,12 @@ is \code{wb_blue}.} A \link{ggplot2} theme. } \description{ -These are wrappers for \code{theme_paleta()} that use colours and fonts from the +These are wrappers for \code{\link[=theme_paleta]{theme_paleta()}} that use colours and fonts from the World Bank visual identity guidelines. } \section{Colours}{ -The World Bank theme is based on the colours from the \code{wb_palettes}. The +The World Bank theme is based on the colours from the \link{wb_palettes}. The primary palette consists of four colours: \code{wb_palettes$wb_primary}. The secondary palette consists of fourteen colours: \code{wb_palettes$wb_secondary}. } diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 395bee7..e3b5446 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -54,6 +54,10 @@ reference: - paleta_fonts - set_paleta_font - theme_paleta + + - title: Palette Brewer + contents: + - starts_with("paleta_create") - title: Africa CDC contents: