Examples for 'GGally::grab_legend'


Grab the legend and print it as a plot

Aliases: grab_legend print.legend_guide_box

Keywords:

### ** 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)
plot of chunk example-GGally-grab_legend-1
(bottom <- histPlot + theme(legend.position = "bottom"))
plot of chunk example-GGally-grab_legend-1
(top <- histPlot + theme(legend.position = "top"))
plot of chunk example-GGally-grab_legend-1
(left <- histPlot + theme(legend.position = "left"))

p_(grab_legend(right))
p_(grab_legend(bottom))
p_(grab_legend(top))
p_(grab_legend(left))
plot of chunk example-GGally-grab_legend-1

[Package GGally version 2.1.2 Index]