gglegend: Plot only legend of plot function

Description Usage Arguments Value Examples

View source: R/ggmatrix_legend.R

Description

Plot only legend of plot function

Usage

1

Arguments

fn

this value is passed directly to an empty wrap call. Please see ?wrap for more details.

Value

a function that when called with arguments will produce the legend of the plotting function supplied.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# display regular plot
ggally_points(iris, ggplot2::aes(Sepal.Length, Sepal.Width, color = Species))

# Make a function that will only print the legend
points_legend <- gglegend(ggally_points)
points_legend(iris, ggplot2::aes(Sepal.Length, Sepal.Width, color = Species))

# produce the sample legend plot, but supply a string that 'wrap' understands
same_points_legend <- gglegend("points")
identical(
  attr(attr(points_legend, "fn"), "original_fn"),
  attr(attr(same_points_legend, "fn"), "original_fn")
)

# Complicated examples
custom_legend <- wrap(gglegend("points"), size = 6)
custom_legend(iris, ggplot2::aes(Sepal.Length, Sepal.Width, color = Species))

# Use within ggpairs
pm <- ggpairs(
  iris, 1:2,
  mapping = ggplot2::aes(color = Species),
  upper = list(continuous = gglegend("points"))
)
# pm

# Place a legend in a specific location
pm <- ggpairs(iris, 1:2, mapping = ggplot2::aes(color = Species))
# Make the legend
pm[1,2] <- points_legend(iris, ggplot2::aes(Sepal.Width, Sepal.Length, color = Species))
pm

Example output

[1] TRUE

GGally documentation built on May 18, 2018, 1:08 a.m.