Changing legend font

Author

Wyclife Agumba Oluoch

library(geodata)
Loading required package: terra
terra 1.7.78
library(terra)

Get the raster

elev <- geodata::elevation_global(res = 10, path = tempdir())

Plot it

plot(elev)

Increase font

Play around with the arguments in fields::image.plot() function.

plot(elev, legend = FALSE)

# Add a custom legend on the left side with increased font size
fields::image.plot(elev[], legend.only = TRUE, horizontal = FALSE, 
                   zlim = range(values(elev), finite = TRUE), 
                   legend.width = 1.3, legend.shrink = 0.85, 
                   axis.args = list(cex.axis = 1.7),
                   legend.mar = 40, # Adjust margin to make space on the left
                   legend.lab = "Elevation (m)", # Optional: Add a legend label
                   legend.args = list(side = 2, line = 2))