In cartography
several functions have a pos
or legend.pos
argument. These arguments can take the following values: « topleft », « top », « topright », « right », « bottomright », « bottom », « bottomleft », « bottomleftextra », « left » or a vector of two coordinates in map units (c(x, y)).
The posibility to use a vector of coordinates is useful for placing an element at a precise location:
library(sf) library(cartography) mtq <- st_read(system.file("gpkg/mtq.gpkg", package="cartography")) png("poslegend1.png", width = 474, height = 555) par(mar = c(0,0,0,0)) plot(st_geometry(mtq)) # precise location of the bottomleft corner of the legend legpos <- c(717200, 1637100) points(x = legpos[1], y = legpos[2], pch = 4) propSymbolsLayer(x = mtq, var = "POP", legend.pos = legpos) dev.off()
The locator()
function allows users of an interactive R session to click on a graphic device to obtain coordinates of the cursor in the device’s coordinate reference system:
One can take advantage of this function to interactively position legends and layout elements on a map with cartography
using unlist(locator(1))
as input for pos
or legend.pos
:
