[R-sig-Geo] raster::plot() common color scale?

Robert J. Hijmans r.hijmans at gmail.com
Wed Jun 15 18:56:53 CEST 2011


This works for me. It seems that the new version or raster did not get
loaded properly. Can you close & open R and try again? Perhaps without
loading the previous session. Robert

On Wed, Jun 15, 2011 at 8:12 AM, Agustin Lobo <alobolistas at gmail.com> wrote:
> Robert,
>
> I've tried with raster_1.8-35
> but:
>
> other attached packages:
> [1] raster_1.8-35 ggplot2_0.8.9 proto_0.3-8   reshape_0.8.4 plyr_1.4
> [6] plotrix_3.2-2 sp_0.9-76     rkward_0.5.6
>
> loaded via a namespace (and not attached):
> [1] digest_0.4.2    lattice_0.19-26 tools_2.13.0
>
>
>> foo1 <- foo2 <- foo3<- foo4 <- raster(nrows=20, ncols=20)
>> values(foo1) <- runif(400,-100.100)
>> values(foo2) <- runif(400,-150,100)
>> values(foo3) <- runif(400,0,50)
>> values(foo4) <- runif(400,-100,150)
>> extent(foo1) = extent(foo2) = extent(foo3) = extent(foo4) = extent(c(0,20,0,20))
>> s <- stack(foo1,foo2,foo3,foo4)
>
>> spplot(as(x, 'SpatialGridDataFrame'))
> Error in rk.record.plot$.save.tlo.in.hP() :
>  could not find function "trellis.last.object"
> Calls: print ... print -> print.trellis -> printFunction -> <Anonymous>
>> spplot(s)
> Error in function (classes, fdef, mtable)  :
>  unable to find an inherited method for function "spplot", for
> signature "RasterStack"
> Calls: spplot -> <Anonymous>
>> theme_set(theme_bw())
> + gplot(s) + geom_tile(aes(fill = value)) + facet_wrap(~ variable) +
> +            scale_fill_gradient(low = 'white', high = 'blue') +
> + coord_equal()
> Error: could not find function "gplot"
>> theme_set(theme_bw())
> + ggplot(s) + geom_tile(aes(fill = value)) + facet_wrap(~ variable) +
> +            scale_fill_gradient(low = 'white', high = 'blue') +
> + coord_equal()
> Error: ggplot2 doesn't know how to deal with data of class RasterStack
>>
>
>
> Agus
>
> 2011/6/11 Robert Hijmans <r.hijmans at gmail.com>:
>>> 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.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>



More information about the R-sig-Geo mailing list