grab_legend: Grab the legend and print it as a plot

Description Usage Arguments Examples

View source: R/grab_legend.R

Description

Grab the legend and print it as a plot

Usage

1
2
3
4
grab_legend(p)

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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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"))

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

schloerke/gsoc-ggduo-test documentation built on May 29, 2019, 3:41 p.m.