Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

grab_legend

Grab the legend and print it as a plot


Description

Grab the legend and print it as a plot

Usage

grab_legend(p)

## S3 method for class 'legend_guide_box'
print(x, ..., plotNew = FALSE)

Arguments

p

ggplot2 plot object

x

legend object that has been grabbed from a ggplot2 object

...

ignored

plotNew

boolean to determine if the grid.newpage() command and a new blank rectangle should be printed

Examples

# Small function to display plots only if it's interactive
p_ <- GGally::print_if_interactive

library(ggplot2)
histPlot <- qplot(
  x = Sepal.Length,
  data = iris,
  fill = Species,
  geom = "histogram",
  binwidth = 1/4
)
(right <- histPlot)
(bottom <- histPlot + theme(legend.position = "bottom"))
(top <- histPlot + theme(legend.position = "top"))
(left <- histPlot + theme(legend.position = "left"))

p_(grab_legend(right))
p_(grab_legend(bottom))
p_(grab_legend(top))
p_(grab_legend(left))

GGally

Extension to 'ggplot2'

v2.1.1
GPL (>= 2.0)
Authors
Barret Schloerke [aut, cre], Di Cook [aut, ths], Joseph Larmarange [aut], Francois Briatte [aut], Moritz Marbach [aut], Edwin Thoen [aut], Amos Elberg [aut], Ott Toomet [ctb], Jason Crowley [aut], Heike Hofmann [ths], Hadley Wickham [ths]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.