diff --git a/NAMESPACE b/NAMESPACE index bb1977c..d259fdd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,19 @@ export(acdc_text) export(acdc_white) export(get_colour) export(get_colours) +export(gnc_aqua_green) +export(gnc_blue) +export(gnc_cyan) +export(gnc_dark_green) +export(gnc_fonts) +export(gnc_gold) +export(gnc_green) +export(gnc_grey) +export(gnc_lime) +export(gnc_moss_green) +export(gnc_orange) +export(gnc_palettes) +export(gnc_sage) export(nhs_aqua_blue) export(nhs_aqua_green) export(nhs_black) @@ -55,6 +68,7 @@ export(paleta_create_qualitative) export(paleta_create_sequential) export(paleta_fonts) export(set_acdc_font) +export(set_gnc_font) export(set_nhs_font) export(set_paleta_font) export(set_unicef_font) @@ -64,6 +78,7 @@ export(shade_colours) export(shade_colours_) export(theme_acdc_dark) export(theme_acdc_light) +export(theme_gnc) export(theme_nhs) export(theme_unicef) export(theme_wb) diff --git a/NEWS.md b/NEWS.md index 2b787ce..13f2487 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,11 +2,13 @@ ## Major changes -* Changed Africa CDC colour palettes based on updated communication style guidelines +* changed Africa CDC colour palettes based on updated communication style guidelines -* Created Africa CDC brewer base palettes +* created Africa CDC brewer base palettes -* Created palette brewer functions for sequential, divergent, and qualitative colour palettes +* created NHS brewer base palettes + +* created palette brewer functions for sequential, divergent, and qualitative colour palettes ## General updates diff --git a/R/theme_gnc.R b/R/theme_gnc.R new file mode 100644 index 0000000..4239339 --- /dev/null +++ b/R/theme_gnc.R @@ -0,0 +1,303 @@ +#' +#' GNC colours +#' +#' @examples +#' gnc_green +#' gnc_grey +#' gnc_sage +#' +#' @rdname gnc_colours +#' @export +#' +gnc_green <- "#9CCB38" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_grey <- "#808080" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_sage <- "#94A17F" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_dark_green <- "#63A537" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_lime <- "#37A76F" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_aqua_green <- "#44C1A3" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_cyan <- "#4Eb3CF" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_blue <- "#51C3F9" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_orange <- "#EE7B08" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_moss_green <- "#455F51" + +#' +#' @rdname gnc_colours +#' @export +#' +gnc_gold <- "#89824E" + + +#' +#' GNC palettes +#' +#' @examples +#' gnc_palettes +#' +#' @rdname gnc_palette +#' @export +#' +gnc_palettes <- list( + gnc_primary = gnc_green, + gnc_secondary = c( + gnc_grey, gnc_sage, gnc_dark_green, gnc_lime, gnc_aqua_green, gnc_cyan, + gnc_blue, gnc_orange, gnc_moss_green, gnc_gold + ), + gnc_greens = c( + "#F5F9EB", "#EBF4D7", "#E1EFC3", "#D7EAAF", "#CDE59B", + "#C3DF87", "#B9DA73", "#AFD55F", "#A5D04B", "#9CCB38" + ), + gnc_greys = c( + "#F2F2F2", "#E5E5E5", "#D8D8D8", "#CCCCCC", "#BFBFBF", + "#B2B2B2", "#A6A6A6", "#999999", "#8C8C8C", "#808080" + ), + gnc_sages = c( + "#F4F5F2", "#E9ECE5", "#DEE2D8", "#D4D9CB", "#C9D0BF", + "#BEC6B2", "#B4BDA5", "#A9B398", "#9EAA8B", "#94A17F" + ), + gnc_dark_greens = c( + "#DFEDD7", "#C0DBAF", "#A1C987", "#82B75F", "#63A537" + ), + gnc_limes = c( + "#D7EDE2", "#AFDBC5", "#87CAA8", "#5FB88B", "#37A76F" + ), + gnc_aqua_greens = c( + "#D9F2EC", "#B4E6DA", "#8ED9C7", "#69CDB5", "#44C1A3" + ), + gnc_cyans = c( + "#DBEFF5", "#B8E0EB", "#94D1E2", "#71C2D8", "#4EB3CF" + ), + gnc_blues = c( + "#DCF3FD", "#B9E7FC", "#96DBFB", "#73CFFA", "#51C3F9" + ), + gnc_oranges = c( + "#FBE4CD", "#F8CA9C", "#F4AF6A", "#F19539", "#EE7B08" + ), + gnc_moss_greens = c( + "#D9DFDC", "#B4BFB9", "#8F9F96", "#6A7F73", "#455F51" + ), + gnc_golds = c( + "#E7E6DB", "#CFCDB8", "#B8B494", "#A09B71", "#89824E" + ) +) + + +#' +#' GNC fonts +#' +#' @examples +#' gnc_fonts +#' +#' @rdname gnc_font +#' @export +#' + +gnc_fonts <- list( + gnc_arial = "Arial", + gnc_calibri = "Calibri Regular", + acdc_source_sans_pro = "Source Sans Pro", + acdc_bebas_neue = "Bebas Neue" +) + + +#' +#' Set GNC font to use based on what is available from the system +#' +#' The function will search the system for availability of any of the GNC fonts +#' in hierarchical order starting with *Arial*, then *Calibri Regular*, then +#' *Source Sans Pro*, and then finally *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`. +#' +#' @param alt A character value for font family to use if all of the GNC fonts +#' are not available in the system. +#' +#' @returns A character value for font family to use as GNC font. +#' +#' @examples +#' set_gnc_font() +#' +#' @rdname gnc_font +#' @export +#' + +set_gnc_font <- function(alt = paleta_fonts$paleta_noto) { + ## Detect which fonts are available to the system ---- + fonts <- systemfonts::system_fonts() + + ## Check which GNC font is available ---- + if (any(fonts$family == gnc_fonts$gnc_arial)) { + gnc_font <- gnc_fonts$gnc_arial + } else { + if (any(fonts$family == gnc_fonts$gnc_calibri)) { + gnc_font <- gnc_fonts$gnc_calibri + } else { + if (any(fonts$family == gnc_fonts$gnc_source_sans_pro)) { + gnc_font <- gnc_fonts$gnc_source_sans_pro + } else { + if (any(fonts$family == gnc_fonts$gnc_bebas_neue)) { + gnc_font <- gnc_fonts$gnc_bebas_neue + } else { + gnc_font <- alt + } + } + } + } + + ## Return gnc_font ---- + gnc_font +} + + +#' +#' A [ggplot2] theme using GNC fonts, colours, and palettes +#' +#' These are wrappers for [theme_paleta()] that use colours and fonts from the +#' GNC visual identity guidelines. +#' +#' @section Colours: +#' The GNC theme is based on the colours from the [gnc_palettes]. The +#' primary palette consists of one colour: `gnc_palettes$gnc_primary`. +#' The secondary palette consists of ten colours: +#' `gnc_palettes$gnc_secondary`. +#' +#' @section Fonts: +#' The GNC theme uses four fonts as prescribed by the GNC visual identity +#' guidelines. These fonts (in hierarchical order of preference) are +#' *Arial*, *Calibri*, *Source Sans Pro*, and *Bebas Neue*. Any or all of these +#' fonts should be available in the user's system for them to be used in the +#' theme. If none of these fonts are available in the user's system, a freely +#' downloadable alternative called *Noto Sans* is the default fallback font and +#' can be obtained from [Google Fonts](https://fonts.google.com/). +#' +#' @param base_family Base font family using GNC fonts. Default is set +#' by what GNC font is available in the system via [set_gnc_font()]. +#' If none of the GNC fonts are available, the default becomes +#' *Noto Sans*. +#' @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`. +#' @param plot_title_colour Colour of the plot title text. Default +#' is [gnc_grey]. +#' @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 +#' [gnc_grey]. +#' @param caption_colour Colour of the caption text. Default is +#' [gnc_grey]. +#' @param axis_title_colour Colour of the axis title text. Default is +#' [gnc_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 [gnc_grey]. +#' @param axis_col Axis colours. Default to [gnc_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. +#' @param axis Add x or y axes? `TRUE`, `FALSE`, "`xy`". Default is FALSE. +#' @param ticks Logical. Should ticks be added? Default is FALSE. +#' +#' @returns A [ggplot2] theme. +#' +#' @examples +#' \dontrun{ +#' ggplot( +#' data = mtcars, +#' mapping = aes( +#' x = factor(vs, levels = c(0, 1), labels = c("v-shaped", "straight")), +#' fill = factor(cyl)) +#' ) + +#' geom_bar() + +#' scale_fill_manual( +#' name = "Cylinders", +#' values = gnc_palettes$gnc_secondary +#' ) + +#' labs( +#' title = "Engine shape by number of cylinders", +#' subtitle = "An example plot for this package", +#' x = "Engine Shape", +#' y = "Counts" +#' ) + +#' theme_unicef() +#' } +#' +#' @rdname theme_unicef +#' @export +#' +theme_gnc <- function(base_family = set_gnc_font(), + base_size = 11.5, + plot_title_family = base_family, + plot_title_colour = gnc_grey, + subtitle_family = base_family, + subtitle_colour = gnc_grey, + caption_colour = gnc_grey, + axis_title_colour = gnc_grey, + legend_title_colour = gnc_grey, + legend_text_colour = gnc_grey, + grid_col = gnc_grey, + grid = TRUE, + axis_col = gnc_grey, + axis = FALSE, + ticks = FALSE) { + theme_paleta( + base_family = base_family, + base_size = base_size, + plot_title_family = plot_title_family, + plot_title_colour = plot_title_colour, + subtitle_family = subtitle_family, + subtitle_colour = subtitle_colour, + caption_colour = caption_colour, + axis_title_colour = axis_title_colour, + legend_title_colour = legend_title_colour, + legend_text_colour = legend_text_colour, + grid_col = grid_col, + grid = grid, + axis_col = axis_col, + axis = axis, + ticks = ticks + ) +} \ No newline at end of file diff --git a/R/theme_unicef.R b/R/theme_unicef.R index dddbc34..649dea3 100644 --- a/R/theme_unicef.R +++ b/R/theme_unicef.R @@ -153,7 +153,7 @@ set_unicef_font <- function(alt = paleta_fonts$paleta_noto) { #' `unicef_palettes$unicef_secondary`. #' #' @section Fonts: -#' The UNICEF theme uses two fonts as prescribed by the UNICEF visual identity +#' The UNICEF theme uses four fonts as prescribed by the UNICEF visual identity #' guidelines. These fonts (in hierarchical order of preference) are #' *Univers LT Pro*, *Arial*, *Roboto*, and *Aleo*. Any or all of these fonts #' should be available in the user's system for them to be used in the theme. @@ -169,15 +169,15 @@ set_unicef_font <- function(alt = paleta_fonts$paleta_noto) { #' @param plot_title_family Font family to use for the plot title. Default is #' `base_family`. #' @param plot_title_colour Colour of the plot title text. Default -#' is `unicef_black`. +#' is [unicef_black]. #' @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 -#' `unicef_cool_grey`. +#' [unicef_cool_grey]. #' @param caption_colour Colour of the caption text. Default is -#' `unicef_cool_grey`. +#' [unicef_cool_grey]. #' @param axis_title_colour Colour of the axis title text. Default is -#' `unicef_cool_grey`. +#' [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]. diff --git a/inst/WORDLIST b/inst/WORDLIST index e50c736..b2b4d56 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,9 +1,12 @@ Aleo +Bebas CMD +Calibri CodeFactor Codecov ColorBrewer Frutiger +GNC IBRD ICSID IFC @@ -11,6 +14,7 @@ Katilingban Lifecycle MIGA Netlify +Neue Noto Pantone Roboto diff --git a/man/acdc_palette.Rd b/man/acdc_palette.Rd index 5b66308..c9d7581 100644 --- a/man/acdc_palette.Rd +++ b/man/acdc_palette.Rd @@ -8,7 +8,7 @@ \format{ An object of class \code{list} of length 13. -An object of class \code{list} of length 19. +An object of class \code{list} of length 17. } \usage{ acdc_palettes diff --git a/man/gnc_colours.Rd b/man/gnc_colours.Rd new file mode 100644 index 0000000..35d7a6e --- /dev/null +++ b/man/gnc_colours.Rd @@ -0,0 +1,72 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme_gnc.R +\docType{data} +\name{gnc_green} +\alias{gnc_green} +\alias{gnc_grey} +\alias{gnc_sage} +\alias{gnc_dark_green} +\alias{gnc_lime} +\alias{gnc_aqua_green} +\alias{gnc_cyan} +\alias{gnc_blue} +\alias{gnc_orange} +\alias{gnc_moss_green} +\alias{gnc_gold} +\title{GNC colours} +\format{ +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. + +An object of class \code{character} of length 1. +} +\usage{ +gnc_green + +gnc_grey + +gnc_sage + +gnc_dark_green + +gnc_lime + +gnc_aqua_green + +gnc_cyan + +gnc_blue + +gnc_orange + +gnc_moss_green + +gnc_gold +} +\description{ +GNC colours +} +\examples{ +gnc_green +gnc_grey +gnc_sage + +} +\keyword{datasets} diff --git a/man/gnc_font.Rd b/man/gnc_font.Rd new file mode 100644 index 0000000..5fe0605 --- /dev/null +++ b/man/gnc_font.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme_gnc.R +\docType{data} +\name{gnc_fonts} +\alias{gnc_fonts} +\alias{set_gnc_font} +\title{GNC fonts} +\format{ +An object of class \code{list} of length 4. +} +\usage{ +gnc_fonts + +set_gnc_font(alt = paleta_fonts$paleta_noto) +} +\arguments{ +\item{alt}{A character value for font family to use if all of the GNC fonts +are not available in the system.} +} +\value{ +A character value for font family to use as GNC font. +} +\description{ +The function will search the system for availability of any of the GNC fonts +in hierarchical order starting with \emph{Arial}, then \emph{Calibri Regular}, then +\emph{Source Sans Pro}, and then finally \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}. +} +\examples{ +gnc_fonts + +set_gnc_font() + +} +\keyword{datasets} diff --git a/man/gnc_palette.Rd b/man/gnc_palette.Rd new file mode 100644 index 0000000..4e7ca94 --- /dev/null +++ b/man/gnc_palette.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme_gnc.R +\docType{data} +\name{gnc_palettes} +\alias{gnc_palettes} +\title{GNC palettes} +\format{ +An object of class \code{list} of length 13. +} +\usage{ +gnc_palettes +} +\description{ +GNC palettes +} +\examples{ +gnc_palettes + +} +\keyword{datasets} diff --git a/man/theme_unicef.Rd b/man/theme_unicef.Rd index 5e4de96..19f84c4 100644 --- a/man/theme_unicef.Rd +++ b/man/theme_unicef.Rd @@ -1,9 +1,28 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/theme_unicef.R -\name{theme_unicef} +% Please edit documentation in R/theme_gnc.R, R/theme_unicef.R +\name{theme_gnc} +\alias{theme_gnc} \alias{theme_unicef} -\title{A \link{ggplot2} theme using UNICEF fonts, colours, and palettes} +\title{A \link{ggplot2} theme using GNC fonts, colours, and palettes} \usage{ +theme_gnc( + base_family = set_gnc_font(), + base_size = 11.5, + plot_title_family = base_family, + plot_title_colour = gnc_grey, + subtitle_family = base_family, + subtitle_colour = gnc_grey, + caption_colour = gnc_grey, + axis_title_colour = gnc_grey, + legend_title_colour = gnc_grey, + legend_text_colour = gnc_grey, + grid_col = gnc_grey, + grid = TRUE, + axis_col = gnc_grey, + axis = FALSE, + ticks = FALSE +) + theme_unicef( base_family = set_unicef_font(), base_size = 11.5, @@ -34,19 +53,19 @@ If none of the UNICEF fonts are available, the default becomes \code{base_family}.} \item{plot_title_colour}{Colour of the plot title text. Default -is \code{unicef_black}.} +is \link{unicef_black}.} \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{unicef_cool_grey}.} +\link{unicef_cool_grey}.} \item{caption_colour}{Colour of the caption text. Default is -\code{unicef_cool_grey}.} +\link{unicef_cool_grey}.} \item{axis_title_colour}{Colour of the axis title text. Default is -\code{unicef_cool_grey}.} +\link{unicef_cool_grey}.} \item{legend_title_colour}{Colour of the legend title text. Default is NULL.} @@ -65,14 +84,25 @@ is \code{unicef_black}.} \item{ticks}{Logical. Should ticks be added? Default is FALSE.} } \value{ +A \link{ggplot2} theme. + A \link{ggplot2} theme. } \description{ +These are wrappers for \code{\link[=theme_paleta]{theme_paleta()}} that use colours and fonts from the +GNC visual identity guidelines. + These are wrappers for \code{\link[=theme_paleta]{theme_paleta()}} that use colours and fonts from the UNICEF visual identity guidelines. } \section{Colours}{ +The GNC theme is based on the colours from the \link{gnc_palettes}. The +primary palette consists of one colour: \code{gnc_palettes$gnc_primary}. +The secondary palette consists of ten colours: +\code{gnc_palettes$gnc_secondary}. + + 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: @@ -81,7 +111,16 @@ The secondary palette consists of eleven colours: \section{Fonts}{ -The UNICEF theme uses two fonts as prescribed by the UNICEF visual identity +The GNC theme uses four fonts as prescribed by the GNC visual identity +guidelines. These fonts (in hierarchical order of preference) are +\emph{Arial}, \emph{Calibri}, \emph{Source Sans Pro}, and \emph{Bebas Neue}. Any or all of these +fonts should be available in the user's system for them to be used in the +theme. If none of these fonts are available in the user's system, a freely +downloadable alternative called \emph{Noto Sans} is the default fallback font and +can be obtained from \href{https://fonts.google.com/}{Google Fonts}. + + +The UNICEF theme uses four fonts as prescribed by the UNICEF visual identity guidelines. These fonts (in hierarchical order of preference) are \emph{Univers LT Pro}, \emph{Arial}, \emph{Roboto}, and \emph{Aleo}. Any or all of these fonts should be available in the user's system for them to be used in the theme. @@ -91,6 +130,27 @@ can be obtained from \href{https://fonts.google.com/}{Google Fonts}. } \examples{ +\dontrun{ + ggplot( + data = mtcars, + mapping = aes( + x = factor(vs, levels = c(0, 1), labels = c("v-shaped", "straight")), + fill = factor(cyl)) + ) + + geom_bar() + + scale_fill_manual( + name = "Cylinders", + values = gnc_palettes$gnc_secondary + ) + + labs( + title = "Engine shape by number of cylinders", + subtitle = "An example plot for this package", + x = "Engine Shape", + y = "Counts" + ) + + theme_unicef() +} + \dontrun{ ggplot( data = mtcars, diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 87b4245..1129700 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -59,11 +59,12 @@ reference: contents: - starts_with("paleta_create") - - title: Africa CDC + - title: Africa Centres for Disease Control and Prevention contents: + - acdc_fonts + - set_acdc_font - acdc_palettes - acdc_brewer_palettes - - acdc_fonts - acdc_green - acdc_red - acdc_gold @@ -87,8 +88,9 @@ reference: - title: World Bank contents: - - wb_palettes - wb_fonts + - set_wb_font + - wb_palettes - wb_blue - wb_cyan - wb_bright_orange @@ -107,10 +109,11 @@ reference: - wb_dark_green - theme_wb - - title: UNICEF + - title: United Nations Children's Fund contents: - - unicef_palettes - unicef_fonts + - set_unicef_font + - unicef_palettes - unicef_blue - unicef_green - unicef_lime_green @@ -125,11 +128,12 @@ reference: - unicef_dark_blue - theme_unicef - - title: NHS + - title: National Health Service contents: + - nhs_fonts + - set_nhs_font - nhs_palettes - nhs_brewer_palettes - - nhs_fonts - nhs_blue - nhs_white - nhs_dark_blue @@ -153,6 +157,24 @@ reference: - nhs_yellow - theme_nhs + - title: Global Nutrition Cluster + contents: + - gnc_fonts + - set_gnc_font + - gnc_palettes + - gnc_green + - gnc_grey + - gnc_sage + - gnc_dark_green + - gnc_lime + - gnc_aqua_green + - gnc_cyan + - gnc_blue + - gnc_orange + - gnc_moss_green + - gnc_gold + - theme_gnc + - title: Utilities contents: - get_colour