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/">