R/theme_tpl.R

Defines functions theme_tpl

Documented in theme_tpl

#' Customize a ggplot theme
#'
#' This function sets a custom theme in line with the TPL style guide for visualizations made with ggplot. This function does not have any pre-sets for a plot legend. It can be layered on to any ggplot visualization just like a built-in theme.
#'
#'
#' @return A layer to be added to a ggplot visualization that modifies non-data features
#' @export

#define theme_tpl() function

theme_tpl <- function(){

  ggplot2::theme_classic() %+replace% #modifying the built-in ggplot theme

    ggplot2::theme(

      #text elements
      text = ggplot2::element_text(family = "Open Sans", face = "plain"),
      plot.title = ggplot2::element_text(size = 18, color = "gray30", hjust = 0, vjust = 0),
      plot.subtitle = ggplot2::element_text(size = 14, color = "gray30", hjust = 0, vjust = 0),
      axis.text = ggplot2::element_text(size = 16, color = "gray30"),
      axis.title = ggplot2::element_text(size = 16, color = "gray30"),
      strip.text = ggplot2::element_text(size = 14, color = "gray30"),

      #ticks and grid elements
      axis.ticks = ggplot2::element_blank(),
      panel.grid.major.y = ggplot2::element_blank(),
      axis.line.y.left = ggplot2::element_blank(),
      axis.line.x.bottom = ggplot2::element_line(color = "gray"),

      #caption elements
      plot.caption = ggplot2::element_text(hjust = 0, size = 12, color = "gray30")

    )

}
heidiwallace/TPLthemeR documentation built on Jan. 21, 2022, 9:21 p.m.