R/pvar_get_legend_fun.R

Defines functions get_legend

# function for getting legend from the plot
#' @export
get_legend <- function(myggplot){
  pdf(NULL) # Workaround for bug in ggplot_gtable causing empty Rplots.pdf to be created
  tmp <- ggplot_gtable(ggplot_build(myggplot))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  graphics.off()
  return(legend)
}
UUPharmacometrics/PsNR documentation built on June 30, 2023, 8:34 a.m.