I use plot function to plot a raster in R. The plot function adds a legend as default. However, the default legend added does not have a title. For instance I need to add the unit such as meters.

I cannot add a title to legend. How can I do it in plot function?

plot(raster, main = "text", sub = "This is elevation", lwd =5, col =my.palette, legend = T )

1 Answer 1


You can add a title to the legend using legend.args in the call to plot the raster. E.g:

plot(elevRaster, legend.args = list(text = 'Elevation (m)', side = 4, 
         font = 2, line = 2.5, cex = 0.8))

The above snippet is taken from this question where you can also find a few more expansive examples of how the legend can be formatted (for the raster package): https://stackoverflow.com/questions/9436947/legend-properties-when-legend-only-t-raster-package

  • It is a great help. Thanks.
    – BabakK
    Jun 30, 2019 at 1:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.