[R-sig-Geo] problem using levelplot() + layer() in a function

Gregory Duveiller gduveiller at gmail.com
Thu Mar 20 22:52:11 CET 2014

Dear All…

I am trying to make figures overlaying raster and vectors using the package rasterVis and with the functions levelplot() + layer(). All works well except when I am trying to embed those lines in a function. When I do so, only the raster images come out, not the overlaid layers. Anyone knows what I need to do? The function I have written looks like this:

    footprint=SpatialLines(list(Lines(list(Line(lncoords)),ID='pix')),snr at crs)
    print(levelplot(wstr$r,col.regions=wstr$clrs,margin=FALSE,main=paste('t = ',FootPrint), colorkey = FALSE, scales=list(draw=FALSE)) +
      layer(sp.lines(wstr$spbox, lwd=2, col='black')) +
      layer(sp.lines(footprint, lwd=2, col='red')))

The resulting PDF shows the desired raster background but a text replaces the ‘layers’… mentioning “Error using packet 1 object 'wstr' not found”. But the object in question is there correctly (it is actually a list with data used also to do the levelplot, which is rendered correctly). 

Any ideas?

Is there perhaps a way to include the layers within the levelplot function directly (and avoid ‘adding’ them?)

R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

[1] C

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

other attached packages:
[1] ellipse_0.3-8       rasterVis_0.27      hexbin_1.26.3      
[4] latticeExtra_0.6-26 lattice_0.20-27     raster_2.2-31      
[7] rgdal_0.8-16        sp_1.0-14           RColorBrewer_1.0-5 

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



More information about the R-sig-Geo mailing list