legend_location: Determine location for a legend based on lowest density of...

Description Usage Arguments Value See Also Examples

View source: R/figures_functions_miscellaneous.R

Description

Determine location for a legend based on lowest density of points

Usage

1

Arguments

x

the x and y coordinates of a set of points. Alternatively, a single argument x can be provided.

y

the x and y coordinates of a set of points. Alternatively, a single argument x can be provided.

xlim

A numeric vector of length two. The x-axis limits; derived from data if missing.

ylim

A numeric vector of length two. The y-axis limits; derived from data if missing.

Value

A (character vector) keyword indicating suitable legend location.

See Also

legend, xy.coords

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
xy <- data.frame(
  x = c(rep(1:3, times = 1:3), rep(1:3, times = 3 + 1:3)),
  y = rep(1:2, times = c(6, 15))
)

legend_location(xy)
legend_location(xy, xlim = c(0, 5))
pos <- legend_location(xy, xlim = c(0, 4), ylim = c(1, 4))

if (requireNamespace("KernSmooth")) {
  graphics::smoothScatter(xy, xlim = c(0, 4), ylim = c(1, 4))
} else {
  graphics::plot(xy, xlim = c(0, 4), ylim = c(1, 4))
}
graphics::legend(pos, legend = pos, fill = "black")

DrylandEcology/rSW2analysis documentation built on Nov. 8, 2021, 4:20 p.m.