An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140725/fb8cc04c/attachment.pl>
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:
Hello R-Sig-Geo People! I have a quick question, please: I have two raster layer objects, a and b. I want to plot them on one page. No problem.
par(mfrow=c(1,2))
plot(a)
plot(b)
But I would like to use the same colors for each. How can I do that, please?
Thanks,
Erin
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Michael Sumner Software and Database Engineer Australian Antarctic Division Hobart, Australia e-mail: mdsumner at gmail.com
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:
Hello R-Sig-Geo People! I have a quick question, please: I have two raster layer objects, a and b. I want to plot them on one page. No problem.
par(mfrow=c(1,2))
plot(a)
plot(b)
But I would like to use the same colors for each. How can I do that, please?
Thanks,
Erin
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan