Skip to content

raster plotting question

3 messages · Hodgess, Erin, Michael Sumner, Pascal Oettli

#
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:

  
    
2 days later
#
Hi Erin,

You can stack "a" and "b" together then use the "rasterVis" package to
plot the Raster* object.

Best,
Pascal
On Sat, Jul 26, 2014 at 1:36 AM, Hodgess, Erin <HodgessE at uhd.edu> wrote: