Learn R Programming

pcutils (version 0.2.8)

get_legend2: Get a legend from a ggplot object

Description

Get a legend from a ggplot object

Usage

get_legend2(plot, legend = NULL)

Value

a grob object, or NULL if no legend found

Arguments

plot

a ggplot object

legend

NULL, or position ("top")

Examples

Run this code
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