powered by
Get a legend from a ggplot object
get_legend2(plot, legend = NULL)
a grob object, or NULL if no legend found
a ggplot object
NULL, or position ("top")
library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg, color = mpg)) + geom_point() legend <- get_legend2(p) plot(legend)
Run the code above in your browser using DataLab