I know this variants of question already exist, but I'm still stuck: How do I plot specific categorical levels of a raster in R, using sppplot or ggplot?
Right now I have a raster layer holding soil zinc values, called zn. Here is the information:
class : RasterLayer
dimensions : 1308, 3188, 4169904 (nrow, ncol, ncell)
resolution : 250, 250 (x, y)
extent : -178002.4, 618997.6, 2914810, 3241810 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=45 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
I can plot that variable, along with administrative outlines held in the npadmin1 shapefile, using this code:
spplot(zn, scales = list(draw = FALSE),
col.regions = terrain.colors(100)) +
layer(sp.polygons(npadmin1, lwd = 1))
But I also want to plot 4 levels of the raster value, in 4 colors: 0-.5, .5-1, 1-1.5, >1.5. And then I want the legend to say "low" "medium", "high", "very high". No color bar. I know there are similar questions out there, but (a) I can't seem to get gplot to work at all, and (b) I can't figure out how to do this in spplot. To be honest, I don't really know enough about spplot, ggplot and/or levelsplot to know when each is more appropriate to use.
I'm already aware of the 2 links below... still can't figure it out.
Legend of a raster map with categorical data
Plot continuous raster data in binned classes with ggplot2 in R