R/ggplot_legend.R

Defines functions ggplot_legend

Documented in ggplot_legend

#' ggplot_legend
#' 
#' @param g A ggplot object
#' @return A grob object
#' 
#' @importFrom ggplot2 ggplot_gtable
#' @export
ggplot_legend <- function(g) {
  tmp <- ggplot_gtable(ggplot_build(g))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  return(legend)
}
rpkgs/gg.layers documentation built on Sept. 14, 2024, 11:07 p.m.