R/polyomics_theme.R

Defines functions polyomics_theme

#' Polyomics theme for ggplot graphs
#'
#'@description This Function adds the Glasgow Polyomics theme to ggplot2 graphics
#'
#' @return
#' @export
#'
#' @examples
polyomics_theme <- function() {
  font <- "Helvetica"

  ggplot2::theme(

    #Text format:
    #This sets the font, size, type and colour of text for the chart's title
    plot.title = ggplot2::element_text(family=font,
                                       size=18,
                                       face="bold",
                                       color="#222222"),
    #This sets the font, size, type and colour of text for the chart's subtitle, as well as setting a margin between the title and the subtitle
    plot.subtitle = ggplot2::element_text(family=font,
                                          size=14,
                                          margin=ggplot2::margin(9,0,9,0)),
    # This set the font, size, type and colour of text for the charts caption
    plot.caption = ggplot2::element_text(family=font,
                                         size=10,
                                         face="italic",
                                         color="#222222"),
    #Legend format
    #This sets the position and alignment of the legend, removes a title and backround for it and sets the requirements for any text within the legend. The legend may often need some more manual tweaking when it comes to its exact position based on the plot coordinates.
    legend.position = "top",
    legend.text.align = 0,
    legend.background = ggplot2::element_blank(),
    legend.title = ggplot2::element_blank(),
    legend.key = ggplot2::element_blank(),
    legend.text = ggplot2::element_text(family=font,
                                        size=10,
                                        color="#222222"),

    #Axis format
    #This sets the text font, size and colour for the axis test, as well as setting the margins and removes lines and ticks. In some cases, axis lines and axis ticks are things we would want to have in the chart - the cookbook shows examples of how to do so.
    axis.title = ggplot2::element_text(family=font,
                                       size=12,
                                       face="bold",
                                       color="#222222"),
    axis.text = ggplot2::element_text(family=font,
                                      size=10,
                                      color="#222222"),
    axis.text.x = ggplot2::element_text(margin=ggplot2::margin(5, b = 10)),
    axis.ticks = ggplot2::element_blank(),
    axis.line = ggplot2::element_blank(),

    #Grid lines
    #This removes all minor gridlines and adds major y gridlines. In many cases you will want to change this to remove y gridlines and add x gridlines. The cookbook shows you examples for doing so
    panel.grid.minor = ggplot2::element_blank(),
    panel.grid.major.y = ggplot2::element_line(color="#cbcbcb"),
    panel.grid.major.x = ggplot2::element_blank(),

    #Blank background
    #This sets the panel background as blank
    panel.background = ggplot2::element_blank(),

    #Strip background
    strip.background = ggplot2::element_rect(fill="white"),
    strip.text = ggplot2::element_text(size  = 12,  hjust = 0)
  )
}
GrahamHamilton/PolyomicsTheme documentation built on Oct. 8, 2020, 12:21 a.m.