diff --git a/.Rbuildignore b/.Rbuildignore index d0e1d58..43dbbfb 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,4 @@ ^docs$ ^pkgdown$ ^\.github$ +^codecov\.yml$ diff --git a/.gitignore b/.gitignore index 7ee96ac..3dace83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ .Rproj.user inst/doc - -.Rhistory - *.Rhistory docs diff --git a/DESCRIPTION b/DESCRIPTION index 2ce1c47..1c56dec 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,5 @@ -Package: theme.aagi -Title: Apply AAGI Brand Guidelines to Graphic Output and Create AAGI - Themed Documents +Package: AAGIThemes +Title: Apply AAGI Brand Guidelines to Graphic Outputs and Tables Version: 0.0.1 Authors@R: c( person("Adam H.", "Sparks", , "adam.sparks@dpird.wa.gov.au", role = c("aut", "cre"), @@ -8,22 +7,24 @@ Authors@R: c( person("Kenyon", "Ng", , "kenyon.ng@dpird.wa.gov.au", role = "aut", comment = c(ORCID = "0000-0002-6315-9831")), person("Jimmy", "Ng", , "jimmy.ng@dpird.wa.gov.au", role = "ctb"), - person("Tinula", "Kariyawasam", , "tinula.kariyawasam@dpird.wa.gov.au", role = c("aut")), + person("Tinula", "Kariyawasam", , "tinula.kariyawasam@dpird.wa.gov.au", role = "aut"), person("Matt", "Cowgill", , "matthew.cowgill@grattaninstitute.edu.au", role = "aut", - comment = "Wrote major portions of package for saving charts\n for 'Grattan' package, adapted to 'theme.aagi' under 'MIT'\n licence."), + comment = "Wrote major portions of package for saving charts\n for 'Grattan' package, adapted to 'AAGIThemes' under 'MIT'\n licence."), person("Will", "Mackey", , "william.mackey@grattaninstitute.edu.au", role = "aut", - comment = "Wrote major portions of package for saving charts\n for 'Grattan' package, adapted to 'theme.aagi' under 'MIT'\n licence."), + comment = "Wrote major portions of package for saving charts\n for 'Grattan' package, adapted to 'AAGIThemes' under 'MIT'\n licence."), person("Curtin University of Technology", role = "cph") ) Description: Applies 'AAGI' external brand guidelines to graphics. 'AAGI' colours and font guidelines are applied as useful and reasonable to - both base graphics as well as 'ggplot2' figures and 'flextable' objects. + base graphics, 'ggplot2' figures and 'flextable' objects. License: GPL (>= 3) -URL: https://github.com/AAGI-Org-AU-Public/theme.aagi, https://aagi-org-au-public.github.io/theme.aagi/ -BugReports: https://github.com/AAGI-Org-AU-Public/theme.aagi/issues +URL: https://github.com/AAGI-Org-AU-Public/AAGIThemes, + https://aagi-org-au-public.github.io/AAGIThemes/ +BugReports: https://github.com/AAGI-Org-AU-Public/AAGIThemes/issues Depends: R (>= 4.0.0) Imports: + AAGIPalettes, cli, flextable, ggplot2 (>= 3.3.5), @@ -31,7 +32,6 @@ Imports: grid, magick, officer, - rlang, scales, showtext, sysfonts, @@ -52,6 +52,8 @@ Suggests: viridis VignetteBuilder: knitr +Remotes: + AAGI-Org-AU-Public/AAGIPalettes Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US @@ -59,4 +61,5 @@ LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 X-schema.org-applicationCategory: Tools -X-schema.org-isPartOf: https://grdc.com.au/research/partnerships-and-initiatives/strategic-partnerships/aagi +X-schema.org-isPartOf: + https://grdc.com.au/research/partnerships-and-initiatives/strategic-partnerships/aagi\ diff --git a/NAMESPACE b/NAMESPACE index f074e82..e95e0ee 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,15 +1,10 @@ # Generated by roxygen2: do not edit by hand -export(aagi_cols) -export(aagi_palettes) export(add_aagi_logo) export(barplot_aagi) export(boxplot_aagi) export(hist_aagi) -export(interpolate_aagi_palette) export(plot_aagi) -export(scale_colour_aagi) -export(scale_fill_aagi) export(theme_aagi) export(theme_ft_aagi) export(watermark) diff --git a/NEWS.md b/NEWS.md index 00740c7..4f42484 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,2 +1,2 @@ -# theme.aagi 0.0.1 +# AAGIThemes 0.0.1 diff --git a/R/aagi_cols.R b/R/aagi_cols.R deleted file mode 100644 index 9209578..0000000 --- a/R/aagi_cols.R +++ /dev/null @@ -1,12 +0,0 @@ -#' Extract AAGI Colours as Hex Codes -#' -#' @param ... Character names of \acronym{AAGI} colours -#' @export -aagi_cols <- function(...) { - cols <- c(...) - - if (is.null(cols)) - return(theme.aagi::aagi_colours) - - theme.aagi::aagi_colours[cols] -} diff --git a/R/aagi_ggplot2_scales.R b/R/aagi_ggplot2_scales.R deleted file mode 100644 index f2999e2..0000000 --- a/R/aagi_ggplot2_scales.R +++ /dev/null @@ -1,81 +0,0 @@ -#' Construct AAGI Colour Scales for ggplot2 -#' -#' Uses AAGI colours to create colour scales suitable for use in -#' \CRANpkg{ggplot2} objects. -#' -#' @param palette `Character` name of a \acronym{AAGI} palette from -#' [aagi_palettes()]. Defaults to `colourful`. -#' -#' ## Available Palettes -#' -#' \describe{ -#' \item{primary}{The three primary \acronym{AAGI} colours} -#' \item{secondary}{The three secondary support colours in the \acronym{AAGI} -#' colour palette} -#' \item{full}{The full set of all six colours in the \acronym{AAGI} -#' palette} -#' \item{colourful}{All colours in the palette minus \dQuote{AAGI Black}} -#' \item{bright}{Four \dQuote{bright} colours including, -#' \dQuote{AAGI Bright Green}, \dQuote{AAGI Blue} and \dQuote{AAGI Yellow}} -#' \item{bluegreeen}{Three blue, green or bluegreen \acronym{AAGI} colours -#' including \dQuote{AAGI Bright Green}, \dQuote{AAGI Turquoise}, -#' \dQuote{AAGI Blue}, \dQuote{AAGI Green} and \dQuote{AAGI Bluegreen}} -#' } -#' @param palette `Character` string, one of: -#' * "primary", -#' * "secondary", -#' * "colourful" (default), -#' * "full", -#' * "bright", or -#' * "bluegreen". -#' @param discrete `Boolean` argument indicating whether colour aesthetic is -#' discrete, _e.g._, a `factor` (`TRUE`) or continuous, _e.g._, `numeric` -#' (`FALSE`). -#' @param reverse `Boolean` argument indicating whether the palette should be -#' reversed, _i.e._, light to dark. Defaults to `FALSE`. -#' @param ... Additional arguments passed to `discrete_scale()` or -#' [ggplot2::scale_colour_gradientn], used respectively when -#' discrete is `TRUE`. -#' -#' @seealso [aagi_palettes] [scale_fill_aagi] -#' @export -#' -scale_colour_aagi <- - function(palette = "colourful", - discrete = TRUE, - reverse = FALSE, - ...) { - selected_pal <- interpolate_aagi_palette()[palette] - - if (discrete) { - ggplot2::discrete_scale("colour", - sprintf("aagi%s", selected_pal), - palette = selected_pal, ...) - } else { - ggplot2::scale_colour_gradientn(colours = interpolate_aagi_palette(n = 256), ...) - } - } - -#' Construct AAGI Colour Fill Scales for ggplot2 -#' -#' Uses AAGI colours to create fill colour scales suitable for use in -#' \CRANpkg{ggplot2} objects. -#' -#' @inherit scale_colour_aagi params -#' @seealso [aagi_palettes()] [scale_colour_aagi()] -#' @export -#' -#' -scale_fill_aagi <- - function(palette = "colourful", - discrete = TRUE, - reverse = FALSE, - ...) { - selected_pal <- interpolate_aagi_palette(palette = palette, reverse = reverse) - - if (discrete) { - ggplot2::discrete_scale(aesthetics = "fill", palette = selected_pal, ...) - } else { - ggplot2::scale_fill_gradientn(colours = interpolate_aagi_palette(n = 256), ...) - } - } diff --git a/R/aagi_palettes.R b/R/aagi_palettes.R deleted file mode 100644 index 29b1457..0000000 --- a/R/aagi_palettes.R +++ /dev/null @@ -1,39 +0,0 @@ - -#' List AAGI Palette Colour Combinations -#' -#' Returns a list of curated palettes of \acronym{AAGI} colours, which includes: -#' \describe{ -#' \item{primary}{The three primary \acronym{AAGI} colours} -#' \item{secondary}{The three secondary support colours in the \acronym{AAGI} -#' colour palette.} -#' \item{full}{The full set of all six colours in the \acronym{AAGI} -#' palette} -#' \item{colourful}{All colours in the palette minus \dQuote{AAGI Black}} -#' \item{bright}{Four \dQuote{bright} colours including, -#' \dQuote{AAGI Bright Green}, \dQuote{AAGI Blue} and \dQuote{AAGI Yellow}} -#' \item{bluegreeen}{Three blue, green or bluegreen \acronym{AAGI} colours -#' including \dQuote{AAGI Bright Green}, \dQuote{AAGI Turquoise}, -#' \dQuote{AAGI Blue}, \dQuote{AAGI Green} and \dQuote{AAGI Bluegreen}} -#' } -#' -#' @examples -#' # View all five palettes' names and hexadecimal colour codes -#' aagi_palettes() -#' aagi_palettes()$colourful -#' aagi_palettes()$bluegreen -#' -#' @return A `list` object of \acronym{AAGI} colours grouped by palette -#' combinations -#' @export -aagi_palettes <- function() { - return( - list( - "primary" = theme.aagi::aagi_colours[1:3], - "secondary" = theme.aagi::aagi_colours[4:6], - "colourful" = theme.aagi::aagi_colours[2:6], - "full" = theme.aagi::aagi_colours, - "bright" = theme.aagi::aagi_colours[c(2, 4, 6)], - "bluegreen" = theme.aagi::aagi_colours[3:5] - ) - ) -} diff --git a/R/add_aagi_logo.R b/R/add_aagi_logo.R index b5326d2..e500010 100644 --- a/R/add_aagi_logo.R +++ b/R/add_aagi_logo.R @@ -1,9 +1,8 @@ - #' Insert AAGI's Logo Into Any Graphic File #' #' Insert the \acronym{AAGI} logo in any graphical image. Particularly well- -#' suited for use with files created with \pkg{theme.aagi}. The logo will be +#' suited for use with files created with \pkg{AAGIThemes}. The logo will be #' inserted in the upper-left of the image with a size of at least 4.6 cm as #' per \acronym{AAGI} brand guidelines. #' @@ -57,7 +56,7 @@ add_aagi_logo <- function(file_in, file_out, logo_scale = 2.5) { system.file( "logo", "AAGI_logo_colour_CMYK.svg", - package = "theme.aagi", + package = "AAGIThemes", mustWork = TRUE ) ) @@ -67,7 +66,7 @@ add_aagi_logo <- function(file_in, file_out, logo_scale = 2.5) { system.file( "logo", "AAGI_logo_colour_CMYK.svg", - package = "theme.aagi", + package = "AAGIThemes", mustWork = TRUE ) ) @@ -90,8 +89,8 @@ add_aagi_logo <- function(file_in, file_out, logo_scale = 2.5) { # trim plot down, removes bottom border added earlier to make room for logo plot_out <- magick::image_crop(plot_out, - geometry = paste0("0x", plot_height + 300), - gravity = "north") + geometry = paste0("0x", plot_height + 300), + gravity = "north") magick::image_write(plot_out, file_out) } diff --git a/R/barplot_aagi.R b/R/barplot_aagi.R index 779a841..40a691b 100644 --- a/R/barplot_aagi.R +++ b/R/barplot_aagi.R @@ -1,4 +1,3 @@ - #' Basic Barplots Using a Unified AAGI Style and Typography #' #' @description Basic barplots that follow a standard \acronym{AAGI} style @@ -12,9 +11,11 @@ #' heights of stacked sub-bars making up the bar. If height is a matrix and #' beside is `TRUE`, then the values in each column are juxtaposed rather than #' stacked. -#' @param col Colour to use as fill for bars Defaults to a very dark grey. +#' @param col Colour to use as fill for bars Defaults to "AAGI Black", a very +#' dark grey. Can be supplied as a named AAGI colour; *e.g.*, "AAGI Black"; +#' a named colour, "black"; or a hexadecimal code, "#414042". #' @param ... Arguments to be passed to methods, such as graphical parameters -#' (see [graphics::par]). +#' (see [graphics::par()]). #' #' @examples #' @@ -25,18 +26,21 @@ #' @export #' barplot_aagi <- function(height, - col = "#414042", - ...) { - + col = "AAGI Black", + ...) { + # only validate if the colour is an official AAGI colour and convert to hex + if (substr(col, 1, 5) == "AAGI ") { + # validation/matching is done in {AAGIPalettes} so not needed here + col <- AAGIPalettes::colour_as_hex(col) + } withr::local_par(.new = par_aagi()) - - graphics::plot.new() - withr::local_par(new = TRUE) showtext::showtext_begin() - graphics::barplot(height = height, - col = col, - border = col, - xaxs = "i", - ...) + graphics::barplot( + height = height, + col = col, + border = col, + xaxs = "i", + ... + ) showtext::showtext_end() } diff --git a/R/boxplot_aagi.R b/R/boxplot_aagi.R index 3b86cc3..0b81c5e 100644 --- a/R/boxplot_aagi.R +++ b/R/boxplot_aagi.R @@ -1,4 +1,3 @@ - #' Basic Boxplots Using a Unified AAGI Style and Typography #' #' Basic boxplots that follow \acronym{AAGI} colour and typography guidelines @@ -13,7 +12,9 @@ #' be blank. #' @param xlab X-axis label. Optional. #' @param ylab Y-axis label. Optional. -#' @param col Colour to use as fill and outline for boxes. Defaults to white. +#' @param col Colour to use as fill for boxes Defaults to white. Can be +#' supplied as a named AAGI colour, *e.g.*, "AAGI Orange"; named colour, +#' "Orange"; or or a hexadecimal code, "#ec8525". #' @param pch plotting ‘character’, \emph{i.e.}, symbol to use. This can either #' be a single character or an integer code for one of a set of graphics #' symbols. The full set of S symbols is available with `pch = 0:18`, see the @@ -27,49 +28,40 @@ #' the device, often specified by an argument `pointsize`. For `pch` in 0:25 #' the default size is about 75% of the character height (see `par("cin")`). #' @param ... Arguments to be passed to methods, such as graphical parameters -#' (see [graphics::par]). +#' (see [graphics::par()]). #' -#' @seealso [graphics::boxplot] for full documentation of the basic boxplot +#' @seealso [graphics::boxplot()] for full documentation of the basic boxplot #' capabilities #' @examples #' boxplot_aagi(decrease ~ treatment, -#' data = OrchardSprays, -#' xlab = "treatment", -#' ylab = "decrease") +#' data = OrchardSprays, +#' xlab = "treatment", +#' ylab = "decrease" +#' ) #' @export #' @author Adam Sparks, \email{adam.sparks@@curtin.edu.au} boxplot_aagi <- function(x, - main = "", - sub = "", - xlab = "", - ylab = "", - col = "white", - pch = 16, - ...) { - + main = "", + sub = "", + xlab = "", + ylab = "", + col = "white", + pch = 16, + ...) { # set new pars withr::local_par(.new = par_aagi()) - graphics::plot.new() - graphics::grid( - nx = NA, - ny = NULL, - col = NA - ) - withr::local_par(new = TRUE) showtext::showtext_begin() graphics::boxplot( x, col = scales::alpha(col, 0.5), - border = "#414042", - pars = list( - boxwex = 0.8, - staplelty = 0, - outwex = 0.5, - cex = 1, - whisklty = "solid" - ), + border = AAGIPalettes::colour_as_hex("AAGI Black"), + boxwex = 0.8, + staplelty = 0, + outwex = 0.5, + cex = 1, + whisklty = "solid", title = list(line = 2), main = main, sub = sub, diff --git a/R/data.R b/R/data.R deleted file mode 100644 index f0111c1..0000000 --- a/R/data.R +++ /dev/null @@ -1,17 +0,0 @@ -#' A Vector of AAGI Colour Hex Codes -#' -#' @format A `vector` with three (6) colours as hexadecimal values: -#' \describe{ -#' \item{AAGI AAGI Black}{#414042} -#' \item{AAGI AAGI Bright Green}{#B6D438} -#' \item{AAGI AAGI Teal}{#00808B} -#' \item{AAGI Blue}{#648FD2} -#' \item{AAGI Green}{#54921E} -#' \item{AAGI Yellow}{#FFBC42} -#' } -#' -#' @keywords datasets -#' -#' @family data - -"aagi_colours" diff --git a/R/hist_aagi.R b/R/hist_aagi.R index f74e0de..246c0b9 100644 --- a/R/hist_aagi.R +++ b/R/hist_aagi.R @@ -15,9 +15,9 @@ #' individually with a bar. #' @param col Colour to use as fill for bars Defaults to a very dark grey. #' @param ... Arguments to be passed to methods, such as graphical parameters -#' (see [graphics::par]). +#' (see [graphics::par()]). #' -#' @seealso [graphics::hist] for full documentation of the basic histogram +#' @seealso [graphics::hist()] for full documentation of the basic histogram #' capabilities #' #' @references @@ -42,7 +42,7 @@ hist_aagi <- function(x, xlab = "", ylab = "Count", breaks = "pretty", - col = "#414042", + col = AAGIPalettes::aagi_colours["AAGI Black"], ...) { breaks <- tolower(breaks) diff --git a/R/interpolate_aagi_palette.R b/R/interpolate_aagi_palette.R deleted file mode 100644 index 77b5652..0000000 --- a/R/interpolate_aagi_palette.R +++ /dev/null @@ -1,54 +0,0 @@ - - -#' Interpolate an AAGI Colour Palette to Expand the Colour Values -#' -#' Takes a \acronym{AAGI} colour palette and generates more colours from it, so -#' that there are enough to make your chart. The interpolation method is set -#' to `spline` (the default is `linear`) in an attempt to reduce the number of -#' vomit colours that get produced when generating many colours. -#' -#' @param palette (`character`; default = `colourful`) given name of an -#' \acronym{AAGI} palette: [aagi_palettes()] -#' @param reverse (`Boolean`; default = `FALSE`) indicating if palette should -#' be reversed. -#' @param ... Additional arguments to pass to [grDevices::colorRampPalette], -#' see details here [grDevices::colorRamp]. -#' -#' @returns A function that takes a single value and makes that many colours. -#' -#' @seealso aagi_palettes -#' -#' @examples -#' library(ggplot2) -#' -#' x <- interpolate_aagi_palette("colourful") -#' # round the weights to clean up the legend, this is just an e.g. after all... -#' wt_vals <- x(length(unique(round(mtcars$wt, 1)))) -#' -#' ggplot(mtcars, aes(x = mpg, y = hp, colour = as.factor(round(wt, 1)))) + -#' geom_point() + -#' scale_colour_manual("Weight", values = wt_vals) -#' -#' @export -#' -interpolate_aagi_palette <- function(palette = "colourful", - reverse = FALSE, - ...) { - pal <- rlang::arg_match( - palette, - multiple = FALSE, - values = c( - "colourful", - "primary", - "secondary", - "sequential", - "diverging" - ) - ) - pal <- aagi_palettes()[[palette]] - - if (reverse) - pal <- rev(pal) - - grDevices::colorRampPalette(pal, ..., interpolate = "spline") -} diff --git a/R/plot_aagi.R b/R/plot_aagi.R index 718f0fa..79b454c 100644 --- a/R/plot_aagi.R +++ b/R/plot_aagi.R @@ -1,4 +1,3 @@ - #' Basic X-Y Plotting Using a Unified AAGI Style and Typography #' #' @description Basic X-Y plotting that follows \acronym{AAGI} colour and @@ -14,7 +13,9 @@ #' label if one is available. #' @param xlim Numeric value for x-axis limits. Optional. #' @param ylim Numeric value for y-axis limits. Optional. -#' @param col Colour to use for points. Defaults to a very dark grey. +#' @param col Colour to use for points Defaults to "AAGI Black", a very dark +#' grey. Can be supplied as a named AAGI colour; *e.g.*, "AAGI Black"; +#' a named colour, "black"; or a hexadecimal code, "#414042". #' @param pch plotting ‘character’, \emph{i.e.}, symbol to use. This can either #' be a single character or an integer code for one of a set of graphics #' symbols. The full set of S symbols is available with `pch = 0:18`, see the @@ -22,9 +23,9 @@ #' @param type What type of plot should be drawn. Defaults to `p` for #' **p**oints`` See Section "Type" for more. #' @param ... Arguments to be passed to methods, such as graphical parameters -#' (see [graphics::par]). The most commonly used argument would be +#' (see [graphics::par()]). The most commonly used argument would be #' `type` what type of plot should be drawn. -#" +# " #' @section Type: #' Possible types are: #' \describe{ @@ -55,57 +56,69 @@ #' library(datasets) #' #' plot_aagi(airquality$Ozone, -#' main = "Air Quality", -#' xlab = "Ozone") +#' main = "Air Quality", +#' xlab = "Ozone" +#' ) #' #' @author Adam Sparks, \email{adam.sparks@@curtin.edu.au} #' #' @export #' plot_aagi <- function(x, - y = NULL, - main = "", - sub = "", - xlab = "", - ylab = "", - xlim = NULL, - ylim = NULL, - col = "#414042", - pch = 16, - type = "p", - ...) { - + y = NULL, + main = "", + sub = "", + xlab = "", + ylab = "", + xlim = NULL, + ylim = NULL, + col = "AAGI Black", + pch = 16, + type = "p", + ...) { + # only validate if the colour is an official AAGI colour and convert to hex + if (substr(col, 1, 5) == "AAGI ") { + # validation/matching is done in {AAGIPalettes} so not needed here + col <- AAGIPalettes::colour_as_hex(col) + } if (!missing(xlab)) { - xlab = "" + xlab <- "" } if (!missing(ylab)) { - ylab = "" + ylab <- "" } # set new pars withr::local_par(.new = par_aagi()) xy <- grDevices::xy.coords(x, y) - if (is.null(xlim)) + if (is.null(xlim)) { xlimit <- range(xy$x[is.finite(xy$x)]) - if (is.null(ylim)) + } + if (is.null(ylim)) { ylimit <- range(xy$y[is.finite(xy$y)]) + } graphics::plot.new() showtext::showtext_begin() graphics::plot(NULL, - xlab = xlab, - ylab = ylab, - xlim = xlimit, - ylim = ylimit, - pch = "", - main = main, - sub = sub) + xlab = xlab, + ylab = ylab, + xlim = xlimit, + ylim = ylimit, + pch = "", + main = main, + sub = sub + ) graphics::points(xy$x, xy$y, col = col, pch = pch, type = type) - graphics::axis(col = "#414042", - lty = "solid", - side = 1) - graphics::axis(col = "#414042", - lty = "solid", - side = 2) + graphics::axis( + col = "#414042", + lty = "solid", + side = 1 + ) + graphics::axis( + col = "#414042", + lty = "solid", + side = 2 + ) showtext::showtext_end() } diff --git a/R/theme_aagi.R b/R/theme_aagi.R index 341dfa6..3db0c5b 100644 --- a/R/theme_aagi.R +++ b/R/theme_aagi.R @@ -17,7 +17,7 @@ #' sides, *i.e.*, x-axis, y-axis, top and right sides all will have a black #' border not just x-axis and y-axis. Defaults to `FALSE` with only the #' x-axis and y-axis being outlined in dark grey. -#' @param ... Other arguments as passed along to [ggplot2::theme]. +#' @param ... Other arguments as passed along to [ggplot2::theme()]. #' #' @examples #' @@ -64,14 +64,17 @@ #' @export theme_aagi <- - function(base_size = 12, - major_grid = FALSE, - minor_grid = FALSE, - border = FALSE, - ...) { + function(base_size = 9, + major_grid = FALSE, + minor_grid = FALSE, + border = FALSE, + ...) { # check if Proxima Nova is installed, if not, falls back to Arial aagi_font <- set_aagi_font() + aagi_black <- AAGIPalettes::colour_as_hex("AAGI Black") + aagi_grey <- AAGIPalettes::colour_as_hex("AAGI Grey") + aagi_teal <- AAGIPalettes::colour_as_hex("AAGI Teal") showtext::showtext_auto() @@ -86,11 +89,13 @@ theme_aagi <- ggplot2::theme( # match legend key to panel.background legend.key = ggplot2::element_blank(), + legend.background = ggplot2::element_rect(color = aagi_black, + fill = "#ffffff"), #AAGI colour facet strips strip.background = ggplot2::element_rect( - fill = theme.aagi::aagi_colours[[3]], - colour = theme.aagi::aagi_colours[[3]], - linewidth = base_line_size + fill = aagi_teal, + colour = aagi_teal, + linewidth = base_line_size ), strip.text = ggplot2::element_text( colour = "#ffffff", @@ -119,25 +124,25 @@ theme_aagi <- if (isTRUE(minor_grid)) { theme_aagi <- theme_aagi + ggplot2::theme(panel.grid.minor = - ggplot2::element_line(color = "#e4e4e4", + ggplot2::element_line(color = aagi_grey, linewidth = minor_grid_size)) } if (isTRUE(major_grid)) { theme_aagi <- theme_aagi + ggplot2::theme(panel.grid.major = - ggplot2::element_line(color = "#bdbdbd", + ggplot2::element_line(color = "#bdbdbd", linewidth = major_grid_size)) } if (isTRUE(border)) { theme_aagi <- theme_aagi + ggplot2::theme(panel.border = - ggplot2::element_rect( - fill = NA, - color = "#353535", - size = base_rect_size - )) + ggplot2::element_rect( + fill = NA, + color = aagi_black, + size = base_rect_size + )) } return(theme_aagi) diff --git a/R/theme_ft_aagi.R b/R/theme_ft_aagi.R index 2807644..a4de81a 100644 --- a/R/theme_ft_aagi.R +++ b/R/theme_ft_aagi.R @@ -1,4 +1,3 @@ - #' Apply AAGI Theme to a flextable Object #' #' Apply theme AAGI to a \CRANpkg{flextable}. An \acronym{AAGI} formatted table @@ -17,17 +16,17 @@ #' #' If you want to automatically apply a theme function to each #' \CRANpkg{flextable} object, you can use the `theme_fun` argument of -#' [flextable::set_flextable_defaults]; be aware that this theme function is -#' applied as the last instruction when calling [flextable::flextable] - so if -#' you add headers or footers to the array, they will not be formatted with +#' [flextable::set_flextable_defaults()]; be aware that this theme function is +#' applied as the last instruction when calling [flextable::flextable()] -- so +#' if you add headers or footers to the array, they will not be formatted with #' the theme. #' #' You can also use the `post_process_html` argument of -#' [flextable::set_flextable_defaults] (or `post_process_pdf`, +#' [flextable::set_flextable_defaults()] (or `post_process_pdf`, #' `post_process_docx`, `post_process_pptx`) to specify a theme to be applied -#' systematically before the [flextable::flextable] is printed; in this case, -#' don't forget to take care that the theme doesn't override any formatting -#' done before the print statement. +#' systematically before the [flextable::flextable()] is printed; in this +#' case, don't forget to take care that the theme doesn't override any +#' formatting done before the print statement. #' #' @param x a \CRANpkg{flextable} object #' @return a formatted \CRANpkg{flextable} object @@ -50,11 +49,20 @@ theme_ft_aagi <- function(x) { # header x <- flextable::bold(x = x, bold = TRUE, part = "header") x <- flextable::color(x = x, color = "#ffffff", part = "header") - x <- flextable::bg(x = x, bg = "#00808C", part = "header") + x <- flextable::bg( + x = x, bg = AAGIPalettes::aagi_colours["AAGI Teal"], + part = "header" + ) # body - x <- flextable::color(x = x, color = "#414042", part = "body") - x <- flextable::bg(x = x, bg = "#F2F2F2", part = "body") + x <- flextable::color( + x = x, color = AAGIPalettes::aagi_colours["AAGI Black"], + part = "body" + ) + x <- flextable::bg( + x = x, bg = AAGIPalettes::aagi_colours["AAGI Grey"], + part = "body" + ) x <- flextable::border( x = x, border = officer::fp_border( diff --git a/R/utils.R b/R/utils.R index 2e90edd..b95eb73 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,14 +1,14 @@ #' Set AAGI Font for Figures and Tables With Fallback -#' +#' #' Sets the AAGI font to Proxima Nova first, if it's not available, falls back #' to Arial as per the \acronym{AAGI} comms guide. -#' +#' #' @return A character string with a font family name #' @noRd #' @keywords Internal -#' +#' set_aagi_font <- function() { - if (any(agrepl("Proxima Nova", systemfonts::system_fonts()[, "name"]))) { + if (any(agrepl("Proxima Nova", systemfonts::system_fonts()[, "family"]))) { aagi_font <- "Proxima Nova" } else { aagi_font <- "Arial" @@ -16,21 +16,19 @@ set_aagi_font <- function() { return(aagi_font) } - #' Set Graphical Parameters That Satisfy AAGI's Style Requirements -#' +#' #' @return A list object of graphical parameters #' @noRd #' @keywords Internal -#' +#' par_aagi <- function() { - aagi_font <- set_aagi_font() - list( - family = aagi_font, + return(list( + family = set_aagi_font(), las = 1, mgp = c(2, 0.5, 0), cex = 0.9, bty = "L" - ) + )) } diff --git a/R/zzz.R b/R/zzz.R index 7947704..1e6d98f 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -28,7 +28,7 @@ c("You need to install {cli::symbol$dquote_left}Proxima Nova{cli::symbol$dquote_right} or {cli::symbol$dquote_left}Arial{cli::symbol$dquote_right} TTF fonts to - properly use {.pkg theme.aagi} properly.")) + properly use {.pkg AAGIThemes} properly.")) } } # nocov end diff --git a/README.Rmd b/README.Rmd index 1aa217f..baa3705 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,27 +16,27 @@ knitr::opts_chunk$set( [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) -[![R-CMD-check](https://github.com/AAGI-Org-AU-Public/theme.aagi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AAGI-Org-AU-Public/theme.aagi/actions/workflows/R-CMD-check.yaml) +[![R-CMD-check](https://github.com/AAGI-Org-AU-Public/AAGIThemes/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AAGI-Org-AU-Public/AAGIThemes/actions/workflows/R-CMD-check.yaml) -# {theme.aagi} Apply AAGI Brand Guidelines to R Graphic Output and Create AAGI Themed Documents +# {AAGIThemes} Apply AAGI Brand Guidelines to R Graphic Output and Tables -This repository contains the code for the R package {theme.aagi}, which once installed in your R session (local or RStudio Server), provides helper functions for creating and exporting graphics created in R with a unified style that follows the AAGI brand guidelines. +This repository contains the code for the R package {AAGIThemes}, which once installed in your R session (local or RStudio Server), provides helper functions for creating and exporting graphics created in R with a unified style that follows the AAGI brand guidelines. -The goal of {theme.aagi} is to provide easy to use theming of R graphics for AAGI team members. +The goal of {AAGIThemes} is to provide easy to use theming of R graphics for AAGI team members. Following AAGI's brand guidelines, AAGI colours are used where applicable and the font defaults to Proxima Nova. The resulting graphs, plots and charts feature a x and y axis that meet at 0 with no gridlines, but these can optionally be set to appear. The resulting maps from `theme_aagi_map()` feature a white canvas with the legend on the right. ## Installation instructions -You can install {theme.aagi} like so: +You can install {AAGIThemes} like so: ```r if (!requireNamespace("remotes", quietly = TRUE)) { install.packages("remotes") } -remotes::install_github("AAGI-Org-AU-Public/theme.aagi", +remotes::install_github("AAGI-Org-AU-Public/AAGIThemes", build_vignettes = TRUE, dependencies = TRUE ) @@ -44,20 +44,20 @@ remotes::install_github("AAGI-Org-AU-Public/theme.aagi", ## Quick start -Following are some quick examples of {theme.aagi} functionality. +Following are some quick examples of {AAGIThemes} functionality. However, you may wish to browse the vignette for a more detailed look at what the package offers using: ```r -vignette("Cookbook", package = "theme.aagi") +vignette("Cookbook", package = "AAGIThemes") ``` ### Create Tabular Outputs -{theme.aagi} provides a {flextable} them suited for the AAGI style that works in HTML and Word document outputs. +{AAGIThemes} provides a {flextable} them suited for the AAGI style that works in HTML and Word document outputs. You can use it like so. ```{r tabular} -library(theme.aagi) +library(AAGIThemes) library(dplyr) library(flextable) ft <- flextable(head(airquality) |> @@ -68,7 +68,7 @@ ft ### Plots and graphs -{theme.aagi} provides several functions to assist users in creating plots, charts and graphs with a more unified AAGI style. +{AAGIThemes} provides several functions to assist users in creating plots, charts and graphs with a more unified AAGI style. For creating standalone graphs using R's base library there are: @@ -85,14 +85,14 @@ For creating standalone graphs using R's base library there are: Example of how the base graphics functionality with AAGI style pre-applied is used: ```{r boxplot_aagi} -library(theme.aagi) +library(AAGIThemes) boxplot_aagi(decrease ~ treatment, data = OrchardSprays, xlab = "treatment", ylab = "decrease") ``` -See the respective function's help files and the {theme.aagi} cookbook for more examples and documentation. +See the respective function's help files and the {AAGIThemes} cookbook for more examples and documentation. #### Using With {ggplot2} @@ -102,8 +102,8 @@ No adjustments are made by the type of graph being produced, so you may wish to Example of how `theme_aagi()` is used in a standard {ggplot2} workflow: -```{r theme_aagi} -library(theme.aagi) +```{r theme_aagi_ggboxplot} +library(AAGIThemes) library(ggplot2) ggplot(data = OrchardSprays, aes(x = treatment, y = decrease)) + @@ -111,3 +111,4 @@ ggplot(data = OrchardSprays, aes(x = treatment, y = decrease)) + scale_y_continuous(breaks = seq(0, 120, by = 20)) + theme_aagi() ``` + diff --git a/README.md b/README.md index 729f732..927c042 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,17 @@ [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) -[![R-CMD-check](https://github.com/AAGI-Org-AU-Public/theme.aagi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AAGI-Org-AU-Public/theme.aagi/actions/workflows/R-CMD-check.yaml) +[![R-CMD-check](https://github.com/AAGI-Org-AU-Public/AAGIThemes/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AAGI-Org-AU-Public/AAGIThemes/actions/workflows/R-CMD-check.yaml) -# {theme.aagi} Apply AAGI Brand Guidelines to R Graphic Output and Create AAGI Themed Documents +# {AAGIThemes} Apply AAGI Brand Guidelines to R Graphic Output and Tables -This repository contains the code for the R package {theme.aagi}, which +This repository contains the code for the R package {AAGIThemes}, which once installed in your R session (local or RStudio Server), provides helper functions for creating and exporting graphics created in R with a unified style that follows the AAGI brand guidelines. -The goal of {theme.aagi} is to provide easy to use theming of R graphics +The goal of {AAGIThemes} is to provide easy to use theming of R graphics for AAGI team members. Following AAGI’s brand guidelines, AAGI colours are used where applicable and the font defaults to Proxima Nova. The resulting graphs, plots and charts feature a x and y axis that meet at 0 @@ -26,13 +26,13 @@ legend on the right. ## Installation instructions -You can install {theme.aagi} like so: +You can install {AAGIThemes} like so: ``` r if (!requireNamespace("remotes", quietly = TRUE)) { install.packages("remotes") } -remotes::install_github("AAGI-Org-AU-Public/theme.aagi", +remotes::install_github("AAGI-Org-AU-Public/AAGIThemes", build_vignettes = TRUE, dependencies = TRUE ) @@ -40,21 +40,21 @@ remotes::install_github("AAGI-Org-AU-Public/theme.aagi", ## Quick start -Following are some quick examples of {theme.aagi} functionality. +Following are some quick examples of {AAGIThemes} functionality. However, you may wish to browse the vignette for a more detailed look at what the package offers using: ``` r -vignette("Cookbook", package = "theme.aagi") +vignette("Cookbook", package = "AAGIThemes") ``` ### Create Tabular Outputs -{theme.aagi} provides a {flextable} them suited for the AAGI style that +{AAGIThemes} provides a {flextable} them suited for the AAGI style that works in HTML and Word document outputs. You can use it like so. ``` r -library(theme.aagi) +library(AAGIThemes) library(dplyr) #> #> Attaching package: 'dplyr' @@ -75,7 +75,7 @@ ft ### Plots and graphs -{theme.aagi} provides several functions to assist users in creating +{AAGIThemes} provides several functions to assist users in creating plots, charts and graphs with a more unified AAGI style. For creating standalone graphs using R’s base library there are: @@ -94,7 +94,7 @@ Example of how the base graphics functionality with AAGI style pre-applied is used: ``` r -library(theme.aagi) +library(AAGIThemes) boxplot_aagi(decrease ~ treatment, data = OrchardSprays, xlab = "treatment", @@ -103,7 +103,7 @@ boxplot_aagi(decrease ~ treatment, -See the respective function’s help files and the {theme.aagi} cookbook +See the respective function’s help files and the {AAGIThemes} cookbook for more examples and documentation. #### Using With {ggplot2} @@ -119,7 +119,7 @@ to alter point or line colours in your graph. Example of how `theme_aagi()` is used in a standard {ggplot2} workflow: ``` r -library(theme.aagi) +library(AAGIThemes) library(ggplot2) ggplot(data = OrchardSprays, aes(x = treatment, y = decrease)) + @@ -128,4 +128,4 @@ ggplot(data = OrchardSprays, aes(x = treatment, y = decrease)) + theme_aagi() ``` - + diff --git a/_pkgdown.yml b/_pkgdown.yml index c53ff7d..8b80f8b 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,4 @@ -url: https://aagi-org-au-public.github.io/theme.aagi/ +url: https://aagi-org-au-public.github.io/AAGIThemes/ template: bootstrap: 5 diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/codemeta.json b/codemeta.json index c11303e..530fe78 100644 --- a/codemeta.json +++ b/codemeta.json @@ -1,12 +1,12 @@ { "@context": "https://doi.org/10.5063/schema/codemeta-2.0", "@type": "SoftwareSourceCode", - "identifier": "theme.aagi", - "description": "Applies 'AAGI' external brand guidelines to graphics. 'AAGI' colours and font guidelines are applied as useful and reasonable to both base graphics as well as 'ggplot2' figures and 'flextable' objects.", - "name": "theme.aagi: Apply AAGI Brand Guidelines to Graphic Output and Create AAGI\n Themed Documents", - "relatedLink": "https://aagi-org-au-public.github.io/theme.aagi/", - "codeRepository": "https://github.com/AAGI-Org-AU-Public/theme.aagi", - "issueTracker": "https://github.com/AAGI-Org-AU-Public/theme.aagi/issues", + "identifier": "AAGIThemes", + "description": "Applies 'AAGI' external brand guidelines to graphics. 'AAGI' colours and font guidelines are applied as useful and reasonable to base graphics, 'ggplot2' figures and 'flextable' objects.", + "name": "AAGIThemes: Apply AAGI Brand Guidelines to Graphic Outputs and Tables", + "relatedLink": "https://aagi-org-au-public.github.io/AAGIThemes/", + "codeRepository": "https://github.com/AAGI-Org-AU-Public/AAGIThemes", + "issueTracker": "https://github.com/AAGI-Org-AU-Public/AAGIThemes/issues", "license": "https://spdx.org/licenses/GPL-3.0", "version": "0.0.1", "programmingLanguage": { @@ -228,6 +228,12 @@ "version": ">= 4.0.0" }, "2": { + "@type": "SoftwareApplication", + "identifier": "AAGIPalettes", + "name": "AAGIPalettes", + "sameAs": "https://github.com/AAGI-Org-AU-Public/AAGIPalettes" + }, + "3": { "@type": "SoftwareApplication", "identifier": "cli", "name": "cli", @@ -239,7 +245,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=cli" }, - "3": { + "4": { "@type": "SoftwareApplication", "identifier": "flextable", "name": "flextable", @@ -251,7 +257,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=flextable" }, - "4": { + "5": { "@type": "SoftwareApplication", "identifier": "ggplot2", "name": "ggplot2", @@ -264,17 +270,17 @@ }, "sameAs": "https://CRAN.R-project.org/package=ggplot2" }, - "5": { + "6": { "@type": "SoftwareApplication", "identifier": "grDevices", "name": "grDevices" }, - "6": { + "7": { "@type": "SoftwareApplication", "identifier": "grid", "name": "grid" }, - "7": { + "8": { "@type": "SoftwareApplication", "identifier": "magick", "name": "magick", @@ -286,7 +292,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=magick" }, - "8": { + "9": { "@type": "SoftwareApplication", "identifier": "officer", "name": "officer", @@ -298,18 +304,6 @@ }, "sameAs": "https://CRAN.R-project.org/package=officer" }, - "9": { - "@type": "SoftwareApplication", - "identifier": "rlang", - "name": "rlang", - "provider": { - "@id": "https://cran.r-project.org", - "@type": "Organization", - "name": "Comprehensive R Archive Network (CRAN)", - "url": "https://cran.r-project.org" - }, - "sameAs": "https://CRAN.R-project.org/package=rlang" - }, "10": { "@type": "SoftwareApplication", "identifier": "scales", @@ -373,10 +367,10 @@ "SystemRequirements": null }, "applicationCategory": "Tools", - "isPartOf": "https://grdc.com.au/research/partnerships-and-initiatives/strategic-partnerships/aagi", - "fileSize": "4328.03KB", - "releaseNotes": "https://github.com/AAGI-Org-AU-Public/theme.aagi/blob/master/NEWS.md", - "readme": "https://github.com/AAGI-Org-AU-Public/theme.aagi/blob/main/README.md", - "contIntegration": "https://github.com/AAGI-Org-AU-Public/theme.aagi/actions/workflows/R-CMD-check.yaml", + "isPartOf": "https://grdc.com.au/research/partnerships-and-initiatives/strategic-partnerships/aagi\\", + "fileSize": "4302.933KB", + "releaseNotes": "https://github.com/AAGI-Org-AU-Public/AAGIThemes/blob/master/NEWS.md", + "readme": "https://github.com/AAGI-Org-AU-Public/AAGIThemes/blob/main/README.md", + "contIntegration": "https://github.com/AAGI-Org-AU-Public/AAGIThemes/actions/workflows/R-CMD-check.yaml", "developmentStatus": "https://www.repostatus.org/#active" } diff --git a/data/aagi_colours.rda b/data/aagi_colours.rda deleted file mode 100644 index 539dd72..0000000 Binary files a/data/aagi_colours.rda and /dev/null differ diff --git a/inst/WORDLIST b/inst/WORDLIST index 78af786..f07d9b4 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,34 +1,31 @@ AAGI AAGI's +AAGIPalettes AAGI’s Behaviour Biometrika -Bluegreen CBADA CCDM CMD Colour Colours Curtin -FFBC Grattan Homebrew Hyndman Monash ORCID Proxima -RMarkdown RStudio Sturges XQuartz aagi -bluegreen cairo character’ colour -colourful colours customise +ec flextable fontsize gapminder diff --git a/inst/vector/theme.aagi-hex.svg b/inst/vector/AAGIThemes-hex.svg similarity index 98% rename from inst/vector/theme.aagi-hex.svg rename to inst/vector/AAGIThemes-hex.svg index 57a6140..e24c46b 100644 --- a/inst/vector/theme.aagi-hex.svg +++ b/inst/vector/AAGIThemes-hex.svg @@ -20,7 +20,7 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">theme.aagiAAGIThemestheme.aagiAAGIThemesimage/svg+xmlR theme.aagi package hex sticker SVG file sourceadamhsparksRhexstickerCC0theme.aagiR AAGIThemes package hex sticker SVG file sourceadamhsparksRhexstickerCC0AAGIThemes - %\VignetteIndexEntry{theme.aagi} + %\VignetteIndexEntry{AAGIThemes} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} + %\VignetteDepends{AAGIPalettes} %\VignetteDepends{dplyr} %\VignetteDepends{flextable} %\VignetteDepends{ggplot2} @@ -28,25 +29,23 @@ knitr::opts_chunk$set( ## How to Create AAGI Style Graphics and Tables -The CCDM CBADA team has developed an R package, {theme.aagi}, and this R cookbook to help ease the process of creating publication-ready graphics in our in-house style using R's {graphics}, {ggplot2} and {flextable} libraries a more reproducible process, as well as making it easier for people new to R to create beautiful graphics and tables that adhere to AAGI style guidelines. +The CCDM CBADA team has developed an R package, {AAGIThemes}, and this R cookbook to help ease the process of creating publication-ready graphics in our in-house style using R's {graphics}, {ggplot2} and {flextable} libraries a more reproducible process, as well as making it easier for people new to R to create beautiful graphics and tables that adhere to AAGI style guidelines. ## Getting started -### Install the {theme.aagi} package +### Install the {AAGIThemes} package -{theme.aagi} is not on CRAN, so you will have to install it directly from our GitHub repository using {remotes}. +{AAGIThemes} is not on CRAN, so you will have to install it directly from our GitHub repository using {remotes}. If you do not have the {remotes} package installed, you will have to run the first line in the code below as well. ``` {r eval = FALSE} if (!require("remotes")) - remotes::install_github("AAGI-Org-AU-Public/theme.aagi", - build_vignettes = TRUE) - -) + remotes::install_github("AAGI-Org-AU-Public/AAGIThemes", + build_vignettes = TRUE)) ``` -For more info on {theme.aagi} check out the [package's GitHub repository](https://github.com/AAGI-Org-AU-Public/theme.aagi), but most of the details about how to use the package and its functions are detailed below. +For more info on {AAGIThemes} check out the [package's GitHub repository](https://github.com/AAGI-Org-AU-Public/AAGIThemes), but most of the details about how to use the package and its functions are detailed below. When you have downloaded the package and successfully installed it you are good to go and create plots and tables. @@ -56,7 +55,7 @@ Creating AAGI themed tables requires using {flextable}. Using the `airquality` data set, and adding a text column to illustrate how text columns are handled, here's how to apply an AAGI theme to a table. ```{r flextable} -library("theme.aagi") +library("AAGIThemes") library("flextable") library("dplyr") @@ -68,14 +67,14 @@ ft ### On {ggplot2} Plots and Graphs -Most of the focus of {theme.aagi} is given to supporting {[ggplot2](https://ggplot2.tidyverse.org/R)} visualisations, but {base} and {graphics} plotting functionality are also supported. +Most of the focus of {AAGIThemes} is given to supporting {[ggplot2](https://ggplot2.tidyverse.org/R)} visualisations, but {base} and {graphics} plotting functionality are also supported. The focus is given to {ggplot2} as it is more verbose and efficient in creating data visualization based on "_The Grammar of Graphics_" [@wilkinson2012grammar]. The layered grammar makes developing charts more structural and easy to interpret (after you know how to use {ggplot2} of course). One of the greatest strengths of {ggplot2} is the ability to customise it so easily. Several themes and colour palettes already exist for {ggplot2} to Create the visualisation look professional and engaging for the end users. -{theme.aagi} leverages the ability to customise the appearance {ggplot2} to create a theme that is clean, easy to use and follows AAGI's style guidelines including fonts and colours. +{AAGIThemes} leverages the ability to customise the appearance {ggplot2} to create a theme that is clean, easy to use and follows AAGI's style guidelines including fonts and colours. -When using {theme.aagi} for graphs, the legend will be placed at the top by default and the main and sub-titles will be left aligned and captions will be right aligned. +When using {AAGIThemes} for graphs, the legend will be placed at the top by default and the main and sub-titles will be left aligned and captions will be right aligned. These choices can all be overridden by using `ggplot2::theme()` arguments as you wish. ### Load the Libraries We'll Need @@ -88,8 +87,8 @@ x <- c("dplyr", "gapminder", "ggplot2", - "scales", - "theme.aagi", + "AAGIPalettes", + "AAGIThemes", "tibble") invisible(lapply( X = x, @@ -97,9 +96,9 @@ invisible(lapply( character.only = TRUE )) ``` -## Using {theme.aagi} to Create Graphical Outputs +## Using {AAGIThemes} to Create Graphical Outputs -{theme.aagi} provides several functions to assist users in creating plots, charts and graphs with a more unified AAGI style. +{AAGIThemes} provides several functions to assist users in creating plots, charts and graphs with a more unified AAGI style. Following are examples of four major styles of graphs that are commonly used, bar plots, boxplots, histograms and lines and scatter plots. ### Bar Plots @@ -146,7 +145,7 @@ boxplot_aagi(decrease ~ treatment, #### Using {ggplot2} to Create a Boxplot ```{r boxplot-ggplot2} -library("theme.aagi") +library("AAGIThemes") library("ggplot2") ggplot(data = OrchardSprays, aes(x = treatment, y = decrease)) + @@ -187,7 +186,7 @@ line_df <- gapminder |> plot_aagi( x = line_df$year, y = line_df$lifeExp, - col = aagi_cols("AAGI Turquoise"), + col = AAGIPalettes::colour_as_hex("AAGI Teal"), type = "l", main = "Living longer", xlab = "Year", @@ -200,7 +199,7 @@ plot_aagi( ```{r line-ggplot2} ggplot(line_df, aes(x = year, y = lifeExp)) + - geom_line(colour = aagi_cols("AAGI Turquoise")) + + geom_line(colour = AAGIPalettes::colour_as_hex("AAGI Teal")) + theme_aagi() + ylab("Life expectancy") + xlab("Year") + @@ -233,15 +232,15 @@ ggplot(data = data, aes(x = x, y = y)) + theme_aagi() ``` -## Colours in {theme.aagi} +## Colours in {AAGIThemes} ### AAGI Colours -{theme.aagi} includes official AAGI colours for use in plots and also applies them to {ggplot2} facet strips and uses them in the MS Word and PowerPoint templates for colour matching in the outputs. +{AAGIThemes} imports official AAGI colours for use in plots and also applies them to {ggplot2} facet strips and uses them in the MS Word and PowerPoint templates for colour matching in the outputs from {AAGIPalettes}. ```{r colours} -library(scales) -show_col(aagi_colours) +library(AAGIPalettes) +display_aagi_cols("aagi_colours") ``` ### Using AAGI Colours @@ -249,7 +248,7 @@ show_col(aagi_colours) We've already seen above in the [line graph](#Linegraphs) example how to use the colours in a graph. But for further demonstration, here are a few more examples. -Here we'll again use the {gapminder} data to construct a stacked bar chart and use AAGI's colours `scale_fill_aagi()`. +Here we'll again use the {gapminder} data to construct a stacked bar chart and use AAGI's colours in `scale_fill_manual()`. ```{r aagi-facet-example} #prepare data @@ -274,7 +273,8 @@ ggplot(data = stacked_df, fill = lifeExpGrouped)) + geom_bar(stat = "identity", position = "fill") + - scale_fill_aagi(name = "Life expectancy") + + scale_fill_manual(name = "Life expectancy", + values = aagi_palettes(n = 4, name = "aagi_greens")) + ylab("Continental Population (%)") + xlab("Continent") + theme_aagi() + @@ -301,12 +301,12 @@ facet <- gapminder |> group_by(continent, year) |> summarise(pop = sum(as.numeric(pop))) -col_values <- unname(c( - aagi_cols("AAGI Turquoise"), - aagi_cols("AAGI Green"), - aagi_cols("AAGI Yellow"), - aagi_cols("AAGI Blue") -)) +col_values <- c( + AAGIPalettes::colour_as_hex("AAGI Teal"), + AAGIPalettes::colour_as_hex("AAGI Green"), + AAGIPalettes::colour_as_hex("AAGI Yellow"), + AAGIPalettes::colour_as_hex("AAGI Blue") +) #Make plot p <- ggplot() + @@ -348,7 +348,7 @@ image_read(file.path(tempdir(), "AAGI_logo.png")) |> ## Saving {ggplot2} Figures -When saving figures generated with {ggplot2} that use {theme.aagi} as the theme, PDFs will not properly embed the Proxima Nova font that is used. +When saving figures generated with {ggplot2} that use {AAGIThemes} as the theme, PDFs will not properly embed the Proxima Nova font that is used. In order for you to save your figures and preserve the font, you can either save as a .png file or use the `device` option in `ggsave()`, which is demonstrated as follows. ```{r save-ggplot, eval=TRUE}