0

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

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

library(raster)    
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 at 1:32
  • Glad it helped! If it solved your issue you should consider marking the answer as accepted by checking the mark beneath the option to vote on the answer. This also let's other users know that the issue has been resolved. – humperderp Jul 1 at 13:08

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.