From d417383811e2aeba384c8a649db612b676bee3b8 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Sun, 10 Mar 2024 22:15:34 +0000 Subject: [PATCH] update pkgdown yaml! --- R/theme_unicef.R | 279 ++++++++++++++++++++++++++++++++++++++++ data-raw/colours.R | 39 +++++- data/paleta_colours.rda | Bin 1092 -> 1460 bytes pkgdown/_pkgdown.yml | 8 +- 4 files changed, 321 insertions(+), 5 deletions(-) create mode 100644 R/theme_unicef.R diff --git a/R/theme_unicef.R b/R/theme_unicef.R new file mode 100644 index 0000000..7efa60c --- /dev/null +++ b/R/theme_unicef.R @@ -0,0 +1,279 @@ +#' +#' World Bank colours +#' +#' @examples +#' wb_blue +#' wb_cyan +#' +#' @rdname wb_colours +#' @export +#' +wb_blue <- "#002244" + +#' @rdname wb_colours +#' @export +wb_cyan <- "#009FDA" + +#' @rdname wb_colours +#' @export +wb_black <- "#000000" + +#' @rdname wb_colours +#' @export +wb_white <- "#FFFFFF" + +#' @rdname wb_colours +#' @export +wb_bright_orange <- "#F05023" + +#' @rdname wb_colours +#' @export +wb_bright_yellow <- "#FDB714" + +#' @rdname wb_colours +#' @export +wb_bright_red <- "#EB1C2D" + +#' @rdname wb_colours +#' @export +wb_light_orange <- "#F78D28" + +#' @rdname wb_colours +#' @export +wb_bright_aqua <- "#009CA7" + +#' @rdname wb_colours +#' @export +wb_bright_green <- "#00AB51" + +#' @rdname wb_colours +#' @export +wb_bright_purple <- "#872B90" + +#' @rdname wb_colours +#' @export +wb_light_aqua <- "#00A996" + +#' @rdname wb_colours +#' @export +wb_dark_red <- "#98252B" + +#' @rdname wb_colours +#' @export +wb_dark_orange <- "#E16A2D" + +#' @rdname wb_colours +#' @export +wb_brown <- "#B88C1D" + +#' @rdname wb_colours +#' @export +wb_dark_purple <- "#614776" + +#' @rdname wb_colours +#' @export +wb_dark_aqua <- "#006068" + +#' @rdname wb_colours +#' @export +wb_dark_green <- "#006450" + + +#' +#' Africa CDC palettes +#' +#' @examples +#' wb_palettes +#' +#' @rdname wb_palette +#' @export +#' +wb_palettes <- list( + wb_primary = c("#002244", "#009FDA", "#000000", "#FFFFFF"), + wb_secondary = c( + "#F05023", "#FDB714", "#EB1C2D", "#F78D28", "#009CA7", "#00AB51", "#872B90", + "#00A996", "#98252B", "#E16A2D", "#B88C1D", "#614776", "#006068", "#006450" + ), + wb_brights = c( + "#F05023", "#FDB714", "#EB1C2D", "#F78D28", "#009CA7", "#00AB51", "#872B90", + "#00A996" + ), + 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") +) + + +#' +#' Africa CDC fonts +#' +#' @examples +#' wb_fonts +#' +#' @rdname wb_font +#' @export +#' +wb_fonts <- list( + wb_andes = "Andes", + wb_brandon = "Arial" +) + +#' +#' Set World Bank font to use based on what is available from the system +#' +#' The function will search the system for availability of any of the Africa +#' CDC fonts in heirarchical order starting with *Andes*, 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`. +#' +#' @param alt A character value for font family to use if all of the World Bank +#' fonts are not available in the system. +#' +#' @returns A character value for font family to use as World Bank font. +#' +#' @examples +#' set_wb_font() +#' +#' @rdname wb_font +#' @export +#' + +set_wb_font <- function(alt = paleta_fonts$paleta_noto) { + ## Detect which fonts are available to the system ---- + fonts <- systemfonts::system_fonts() + + ## Check which World Bank font is available ---- + if (any(fonts$family == wb_fonts$wb_andes)) { + wb_font <- wb_fonts$wb_andes + } else { + if (any(fonts$family == wb_fonts$wb_arial)) { + wb_font <- wb_fonts$wb_arial + } else { + wb_font <- alt + } + } + + ## Return wb_font ---- + wb_font +} + + +#' +#' A [ggplot2] theme using World Bank fonts, colours, and palettes +#' +#' These are wrappers for `theme_paleta()` that use colours and fonts from the +#' World Bank visual identity guidelines. +#' +#' @section Colours: +#' The Africa CDC 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`. +#' +#' @section Fonts: +#' The World Bank theme uses two fonts as prescribed by the World Bank visual +#' identity guidelines. These fonts (in hierarchical order of preference) are +#' *Andes* and *Arial*. 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 World Bank fonts. Default is set +#' 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 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 `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 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 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 = wb_palettes$wb_secondary +#' ) + +#' labs( +#' title = "Engine shape by number of cylinders", +#' subtitle = "An example plot for this package", +#' x = "Engine Shape", +#' y = "Counts" +#' ) + +#' theme_wb() +#' } +#' +#' @rdname theme_wb +#' @export +#' +theme_wb <- function(base_family = set_wb_font(), + plot_title_family = base_family, + plot_title_colour = wb_blue, + subtitle_family = base_family, + subtitle_colour = wb_cyan, + caption_colour = wb_blue, + axis_title_colour = wb_blue, + legend_title_colour = wb_blue, + legend_text_colour = wb_blue, + grid_col = wb_cyan, + grid = TRUE, + axis_col = wb_cyan, + axis = FALSE, + ticks = FALSE) { + theme_paleta( + base_family = base_family, + 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 + ) +} + + diff --git a/data-raw/colours.R b/data-raw/colours.R index fbf4dbf..dff333d 100644 --- a/data-raw/colours.R +++ b/data-raw/colours.R @@ -75,6 +75,43 @@ wb_colours <- tibble::tibble( ) -paleta_colours <- rbind(acdc_colours, wb_colours) +## UNICEF colours ---- + +unicef_colours <- tibble::tibble( + organisation = "UNICEF", + name = c( + "UNICEF Blue", "UNICEF Green", "UNICEF Lime Green", "UNICEF Yellow", + "UNICEF Orange", "UNICEF Bright Red", "UNICEF Dark Red", "UNICEF Purple", + "UNICEF Warm Grey", "UNICEF Cool Grey", "UNICEF Black", "UNICEF Dark Blue" + ), + code = c( + "unicef_blue", "unicef_green", "unicef_lime_green", "unicef_yellow", + "unicef_orange", "unicef_bright_red", "unicef_dark_red", "unicef_purple", + "unicef_warm_grey", "unicef_cool_grey", "unicef_black", "unicef_dark_blue" + ), + rgb = c( + "0, 174, 239", "0, 131, 62", "128, 189, 65", "255, 194, 14", "242, 106, 33", + "226, 35, 26", "150, 26, 73", "107, 30, 116", "216, 209, 202", + "119, 119, 122", "45, 41, 38", "55, 78, 162" + ), + cmyk = c( + "100, 0, 0, 0", "97, 22, 100, 9", "55, 3, 100, 0", "0, 25, 100, 0", + "0, 72, 100, 0", "5, 100, 100, 0", "31, 100, 53, 20", "70, 100, 20, 7", + "14, 14, 17, 0", "55, 47, 44, 10", "63, 62, 59, 94", "90, 80, 0, 0" + ), + hex = c( + "#1CABE2", "#00833D", "#80BD41", "#FFC20E", "#F26A21", "#E2231A", "#961A49", + "#6A1E74", "#D8D1C9", "#777779", "#2D2926", "#374EA2" + ), + pantone = c( + "Process Cyan", "356", "376", "7548", "1505", "485", "221", "2613", + "Warm Grey 1", "Cool Grey 9", "Black", "7685" + ) +) + + + + +paleta_colours <- rbind(acdc_colours, wb_colours, unicef_colours) usethis::use_data(paleta_colours, overwrite = TRUE, compress = "xz") diff --git a/data/paleta_colours.rda b/data/paleta_colours.rda index aceb28a3c7d594f2d25c5b1d0f531c27fc2ac534..427ac6e9a5f5a3b9e1d0b229a987b1468c73af01 100644 GIT binary patch delta 1398 zcmV-+1&R8^2($~383Ys`1$U7hI)Ce)iBb|59r94K;6~!bDYmi^18EjkG46NlsM1AL z36-4`V)EZG>?j-%)a!R#WboC7{k{z(oxNSSl7WL*%~J<)GdC1ji94{C`b#cu^Bh6$ z%pK7r%eqv^C8dVv#}Y2U*fOZAXJ8;jZnAX9WV(X0FR0~lXfLP|@!?N6aeoO=DnIET zLb3!9??OZnjNXrdNjKHfv)aDy*6Rt`zXCK_kdwj4`6Z-*6;F2KQT;*?ICtp1s~}n# zi}EAHXMruMSCb1U?g5JC&7@k|&=GOltko%{$sP_$I!f2cEbnV>7Y{+;#Eq*2>}@L@_x`{0F@+{af~atU?|E8}P(32SoIoC@zq zRZ4I+#dae}8{^`i5w`;H_RIs<$Wm3Tlt>*06|K>BY)F!ig&HQw0^ay>=O@uX2mfHq z8rcjG9oox#HM-BUfh~iwv{}AnHZtjzF;YvG0(n(Q!ay)nQPcrc zZTWoG{YmV-$YZZL3x626#E8nLIdW@$HIjxUjZnUh#q)VWg{HC^X zd<~^@X7e!^r`2U#Me^bJpp&#W0$K{6(kOPJG9r0%zDB8;h?!VvP(qw~0cfRrKQoDv z;Hqh|)C9Cj1x43CazySA*~1(g2vm!TN?Vhvn}QLx1^yt^TYm-Tq-4TbROvgUS5~Lu zLn8mW>V#GKq`t;L9-Q~yP05O(vcT|Y*p&WQQyEv!n*&nB;gK4*HG>9>>itXg5zyab zkhYRjmF4aaD@iWQ6G|dqd!Q zq)t^#=&mWCTz}7~+rI%)ndOZrOtSHT`7SDGV6b+Fmx99D$AR^VZQgU6&|O-K_)Hh7 zrb`yB3p>k*3s%>2N$GWq(c+9Rqh<|7#Rhr|0r7VwpsCv1U z(e}xN*8r-=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