legend function

add a custom legend

add a custom legend

Wrapper around legend that allows adding a custom legend to a map using a keyword such as "topleft" or "bottomright". This function will place the legend in the locations within the mapped area as delineated by the axes.

add_legend(x, y, ...)

Arguments

  • x: The keyword to be used to position the legend (or the x coordinate)
  • y: The y coordinate to be used to position the legend (is x is also a coordinate)
  • ...: arguments passed to legend

See Also

add_box, add_grid, add_mtext

Examples

v <- vect(system.file("ex/lux.shp", package="terra")) plot(v) points(centroids(v), col="red") legend("topleft", legend = "centroids", pch = 20, xpd=NA, bg="white", col="red") add_legend("topright", legend = "centroids", pch = 20, col="red")
  • Maintainer: Robert J. Hijmans
  • License: GPL (>= 3)
  • Last published: 2025-02-26

Downloads (last 30 days):