Skip to content
Prev 21377 / 29559 Next

raster plotting question

Use the breaks and cols arguments to (the raster methods for) plot.
See ?raster::plot

This is like the way the ?base::image function operates essentially
you give it one less colour than break (though raster is less fussy):

library(raster)
r <- raster(volcano)
brks <- pretty(cellStats(r, range))
col <- heat.colors(length(brks) - 1)

plot(brick(r, r/1.2), col = col, breaks = brks)

Note that this forces the ticks for the legend, so you can't really
give many more breaks without also creating an ugly legend:

lbrks <- seq(cellStats(r, min), cellStats(r, max), length = 48)
lcol <- heat.colors(length(lbrks) - 1)

plot(brick(r, r/1.2), col = lcol, breaks = lbrks)

You can use the legend and "legend.only" arguments to raster's plot to
turn off default legend painting, but then you are back to controlling
each plot panel too:

op <- par(mfrow = c(1, 2))
plot(r, col = lcol, breaks = lbrks, legend = FALSE)
plot(r, col = col, breaks = brks, legend.only = TRUE)
plot(r/1.2, col = lcol, breaks = lbrks, legend = FALSE)
plot(r, col = col, breaks = brks, legend.only = TRUE)
par(op)

HTH
On Sat, Jul 26, 2014 at 2:36 AM, Hodgess, Erin <HodgessE at uhd.edu> wrote: