R/add_title.R

Defines functions add_title

Documented in add_title

#' @title add_title
#' @description Function to add title to tableGrob.
#'
#' @param tgrob tableGrob
#' @param title Title to add
#' @param flex Boolean indicating if table is for rmarkdown flexdashboard.
#' Defaults to FALSE
#'
#' @return Returns tableGrob with title added.
#' @export
add_title <- function(tgrob, title, flex = FALSE) {
  fontsize <- ifelse(flex, 8, 12)
  title <- textGrob(title, gp = gpar(fontsize = fontsize))

  padding <- unit(5, 'mm')

  tgrob <- gtable::gtable_add_rows(tgrob,
                                  heights = grobHeight(title) + padding,
                                  pos = 0)

  tgrob <- gtable::gtable_add_grob(tgrob, title, t = 1, l = 1, r = ncol(tgrob))

  return(tgrob)
}
kimjam/qrcutils documentation built on May 20, 2019, 10:21 p.m.