Function to add a legend to an existing plot.

draw_legend(x, y, legend, bty = "n", xpd = NA, adj = c(0, 1.2), ...)

Arguments

x

The lower and upper boundaries for the x-axis.

y

The lower and upper boundaries for the y-axis.

legend

A character vector, the text for the legend (see graphics::legend).

bty

A character string, either "o" or "n" (the default), the type of box to draw around the legend (see graphics::legend).

xpd

A logical value or NA, determining how the legend should be clipped relative to the figure region (see graphics::par). Defaults to NA.

adj

A numeric vector of two values, the relative x and y-axis position of the legend, where values are ratios (e.g., values of 1 will place the legend exactly at the top right corner of the figure boundary).

...

Additional arguments to pass to graphics::legend.

Value

Adds a legend to an existing plot.

Examples

# Example figure
x <- 0:1; y <- 0:1
plot_blank(x, y)

# Add legend in middle of figure
draw_legend(
  x, y, 'Example',
  adj = c( .5, .5 )
)