[R-sig-Geo] raster package

Tim Appelhans tim.appelhans at gmail.com
Wed Sep 5 08:17:44 CEST 2012


Dear Celine,
I am not sure whether you can use the native graphics for plotting 
raster objects. Plotting of raster objects is usually done using the 
spplot() function which is built on lattice (ultimately grid) graphics.
In case you want to try if plot() also works, I think you only need two 
:: when calling a package specific function. So, raster::plot(r) should 
work.

Hope that helps,

Tim

On 4/9/2012 21:26, Céline Bellard wrote:
> Hello,
>
> As you see in my example, I can't use plot function from raster 
> library. First thing is that it seems that plot function hasn't the 
> priority over the plot function from graphics package. But even if I 
> use explicitly the plot function from raster package, it don't work. 
> Have you any suggestion ?
>
>> library(raster)
>> r=raster()
>> values(r)=runif(ncell(r))
>> r
> class       : RasterLayer
> dimensions  : 180, 360, 64800  (nrow, ncol, ncell)
> resolution  : 1, 1  (x, y)
> extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84
> data source : in memory
> names       : layer
> values      : 4.09456e-06, 0.9999978  (min, max)
>
>> plot(r)
> Erreur dans as.double(y) :
> cannot coerce type 'S4' to vector of type 'double'
>> detach("package:raster")
>> plot(r)
> Erreur dans as.double(y) :
> cannot coerce type 'S4' to vector of type 'double'
>> library(raster)
>> search()
> [1] ".GlobalEnv"        "package:raster"    "package:sp" "tools:rstudio"
> [5] "package:stats"     "package:graphics"  "package:grDevices" 
> "package:utils"
> [9] "package:datasets"  "package:methods"   "Autoloads" "package:base"
>> raster:::plot(r)
> Erreur dans get(name, envir = asNamespace(pkg), inherits = FALSE) :
> objet 'plot' introuvable
>
> Thank you for your help,
>
> Céline
>

-- 
#####################################
Tim Appelhans
Department of Geography
Environmental Informatics
Philipps Universität Marburg
Deutschhausstraße 12
35032 Marburg (Paketpost: 35037 Marburg)
Germany

Tel +49 (0) 6421 28-25957



More information about the R-sig-Geo mailing list