[R-sig-Geo] raster::plot() common color scale?
Robert Hijmans
r.hijmans at gmail.com
Sat Jun 11 06:38:14 CEST 2011
> Is there any way to
> get a common color scheme
> (i.e., setting common min and max values)?
Here is yet another way:
library(raster)
foo <- raster(nrows=20, ncols=20)
values(foo) <- runif(400)
bar <- raster(nrows=20, ncols=20)
values(bar) <- runif(400)
s <- stack(foo, bar, foo*2)
# first sample large rasters:
x <- sampleRegular(s, 25000, asRaster=T)
# then use spplot
spplot(as(x, 'SpatialGridDataFrame'))
# I have added two functions to raster version 1.8-33
# a generic function for spplot and Raster objects
# that does the same as the example above in one short line:
spplot(s)
# and a wrapper around ggplot (called gplot),
# based on Paul's example, that allows you to do things like:
theme_set(theme_bw())
gplot(s) + geom_tile(aes(fill = value)) + facet_wrap(~ variable) +
scale_fill_gradient(low = 'white', high = 'blue') +
coord_equal()
Robert
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/raster-plot-common-color-scale-tp6457926p6464547.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list