I would like to plot a raster containing 4 different values (1) with a categorical text legend describing the categories such as 2 but with colour boxes.
I've tried using legend such as :
legend( 1,-20,legend = c("land","ocean/lake", "rivers","water bodies"))
but I don't know how to associate one value to the displayed color. Is there a way to retrieve the colour displayed with 'plot' and to use it in the legend?
Raster with legend