Could anyone please help me.
I am plotting raster object (tasc) with 4 seasons: ("DJF","MAM", "JJA", 
"SON") as layers. I get this raster from an Netcdf file. I would like to 
add (overlay) the country polygons (afrc) on top of these 4 plots of 
levelplot.  Levelplot function works quite ok but when I call this plot 
(p) and plot with layer(sp.polygons(afr)), I get this error:

Error in get(x, envir = this, inherits = inh)(this, ...) :
   Need at least one of stat and geom

I have tried all making changes but no success... I followed the example 
on r-forge rasterVis package, but my pc fails even with that example. 
Please any ideas

Here is the piece of code that fails....

setwd("N:/test1/climate_scenarios/seasonal")

     afr<- 
readShapePoly("N:/Climate/hydropower_maps/africa_wgs.shp",proj4string=CRS("+proj=longlat"))
     afrl<- readShapeLines("N:/Climate/hydropower_maps/africa_wgs.shp", 
proj4string=CRS("+proj=longlat"))
     
coaf<-readShapePoly("E:/data/climate/africa_project/southernAfr/southernAfr.shp")
     load("N:\\Climate\\hydropower_maps\\afrc.RData")
     afrc@proj4string@projargs <-" +proj=longlat +ellps=WGS84"
     lsf<-list.files(pattern="tas.nc")

     i=1
#for (i in 1:length(lsf)){
     tas<-brick(lsf[i])
     fnam<-strsplit(lsf[i],".",fixed=TRUE)[[1]][1]
     tas@layernames<-c("DJF","MAM","JJA","SON")
     tasc<-mask(tas,afr)
     tasc@data@values<-round(tasc@data@values-273.15,1) #convert temp 
(K) to (C)

     plotvar<-seq(0,40,by=0.5)
     nclr <- 80
     plotclr<-colorRampPalette(c("skyblue","white","darkred"))(nclr)
     class <- classIntervals(plotvar, nclr, style="pretty")
     colcode <- findColours(class, plotclr)

     pdf(paste(fnam,".pdf",sep=""),width=6,height=4,paper='special')    
# to save plots
     (p<-levelplot(tasc,layers=1:4, labels=list(cex=0.5),at=seq(0,40, 
by=2),par.settings=list(regions=list(col=colcode)),FUN.margin=median, 
contour=TRUE))
    #***** The next line fails
     (p2<-p+layer(sp.polygons(coaf, lwd=0.6, col='darkgray')))
     print(p3<-p2+layer(sp.lines(afrl, lwd=1, col='gray40')))
      dev.off()
          #}

Many thanks in advance  -SessionInfo() below

Byman

sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Norwegian (Bokmål)_Norway.1252  LC_CTYPE=Norwegian 
(Bokmål)_Norway.1252
[3] LC_MONETARY=Norwegian (Bokmål)_Norway.1252 LC_NUMERIC=C
[5] LC_TIME=Norwegian (Bokmål)_Norway.1252

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  
methods   base

other attached packages:
  [1] maps_2.2-5          fts_0.7.7           ggplot2_0.8.9       
proto_0.3-9.2       reshape_0.8.4
  [6] plyr_1.7.1          ncdf_1.6.6          rasterVis_0.10-9    
hexbin_1.26.0       latticeExtra_0.6-19
[11] RColorBrewer_1.0-5  raster_1.9-67       maptools_0.8-14     
lattice_0.20-3      sp_0.9-95
[16] foreign_0.8-49

loaded via a namespace (and not attached):
[1] zoo_1.7-7



	[[alternative HTML version deleted]]

