R/grob_binder.R

Defines functions grob_binder

Documented in grob_binder

#' @title grob_binder
#' @description Function to rbind ggplotGrob and tableGrob. The tableGrob will be placed on the bottom
#'
#' @param ggrob ggplotGrob object
#' @param tgrob tableGrob object
#'
#' @return Returns grob that can be output.
#' @export
grob_binder <- function(ggrob, tgrob) {
  tgrob$heights <- unit.pmax(tgrob$heights)
  tgrob$widths <- unit(rep(1/ncol(tgrob), ncol(tgrob)), 'npc')

  ggrob %<>% gtable_add_rows(., sum(tgrob$heights))
  ggrob %<>% gtable_add_grob(., grobs = tgrob, t = nrow(ggrob),
                             l = 4, b = nrow(ggrob), r = 4)

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