R/g_legend.R

Defines functions g_legend

Documented in g_legend

#' Return legend from ggplot object
#'
#' @param gplot ggplot object from which to get legend
#'
#' @return legend from gplot
#'
#' @import ggplot2
#' @export
g_legend<-function(gplot){
  tmp <- ggplot_gtable(ggplot_build(gplot))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  return(legend)
}
gkane26/rextras documentation built on June 1, 2022, 7:21 p.m.