R/ggplot_theme.R

Defines functions theme_afb afb_cols

Documented in afb_cols theme_afb

#' ggplot theme with the AFB graphic layout
#'
#' @importFrom ggplot2 theme_minimal theme element_text
#'
#' @export
#'
theme_afb <- function(...) {

    theme_minimal() +
        theme(plot.title = element_text(colour = afb_cols("vert"), face = "bold"),
              plot.caption = element_text(face = "italic"),
              axis.title = element_text(colour = afb_cols("bleu"), hjust = 1, face = "bold"),
              strip.text = element_text(colour = afb_cols("orange"), face = "bold", hjust = 0),
              axis.line = element_line(),
              axis.ticks = element_line(),
              ...)

}
# based on https://www.r-bloggers.com/creating-corporate-colour-palettes-for-ggplot2/

#' Function to extract afb colours as hex codes
#'
#' @param ... Character names of afb_colours
#'
#' @export
afb_cols <- function(...) {
    afb_colours <- c(
        `bleu`  = "#39a9dc",
        `vert`  = "#8cc63f",
        `orange`= "#f08b27",
        `marron`= "#986338",
        `gris`  = "#7f8283",
        `noir`  = "#1a1516"
    )

    cols <- c(...)

    if (is.null(cols))
        return (afb_colours)

    afb_colours[cols]
}
CedricMondy/afbBNVD documentation built on May 8, 2019, 9:53 p.m.