Description Usage Arguments Value See Also Examples
View source: R/figures_functions_miscellaneous.R
Determine location for a legend based on lowest density of points
1 |
x |
the x and y coordinates of a set of points.
Alternatively, a single argument |
y |
the x and y coordinates of a set of points.
Alternatively, a single argument |
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. |
A (character vector) keyword indicating suitable legend location.
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.