library(terra)
library(RColorBrewer)
# sample polygon
p <- system.file("ex/lux.shp", package="terra")
p <- terra::vect(p)
# sample raster
r <- system.file("ex/elev.tif", package="terra")
r <- terra::rast(r)
r <- terra::crop(r, p , snap = "out", mask = T)
terra::plot(r,
col = brewer.pal(9, "pastel1"),
cex.main = 2,
smooth = T,
legend = T,
plg = list(title = "Score"),
axes = TRUE,
mar=c(3,3,3,6))
plot(p, add = T)
How do I change the size and orientation of the legend title 'Score'. I want to orient the title so that it is vertical and follows along the legend and also change the size of the legend title?
You can add text wherever you want. For example
library(terra)
p <- terra::vect(system.file("ex/lux.shp", package="terra"))
r <- terra::rast(system.file("ex/elev.tif", package="terra"))
plot(r, mar=c(3,3,3,6))
text(x=6.77, y=49.95, "Score", srt=-90, cex=2, xpd=NA, pos=4)
lines(p)
And with terra version 1.8-35 you can do
plot(r, plg=list(title="Score", title.x=6.71, title.y=49.8,
title.srt=-90, title.cex=1.5))
lines(p)