rspatial / terra

R package for spatial data handling https://rspatial.github.io/terra/reference/terra-package.html
GNU General Public License v3.0
536 stars 89 forks source link

mtext equivalent function #1567

Closed Schuch666 closed 2 months ago

Schuch666 commented 2 months ago

Is there a equivalent function of mtext from base, to include text outside the ploting region of maps using terra::plot() ? There is a way to make it work with mtext or other way to plot outside the map from terra::plot?

rhijmans commented 2 months ago

I have added a new function add_mtext that uses the map's margins.

library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)

plot(r, axes=FALSE, legend=FALSE)
add_box()
for (i in 1:4) add_mtext("margin text", i, cex=i, col=i, line=2-i)

mtext

The function may need some more work to support fancy stuff.

An alternative approach would be to use text(x, y, "text", xpd=TRUE)

Schuch666 commented 2 months ago

Thanks it works!