Skip to content

Instantly share code, notes, and snippets.

@bryanmayer
Created March 13, 2017 21:47
Show Gist options
  • Save bryanmayer/1bfe18dad60365d7016e7602f9963d77 to your computer and use it in GitHub Desktop.
Save bryanmayer/1bfe18dad60365d7016e7602f9963d77 to your computer and use it in GitHub Desktop.
function to extract legend from ggplot2
extract_legend = function(plot_in, theme_in = theme(legend.position = "top"))
gtable::gtable_filter(ggplot_gtable(ggplot_build(plot_in + theme_in)), "guide-box")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment