[R-sig-Geo] sp and latticeExtra: add colorbar for layer drawn 'under'

Ben Tupper btupper at bigelow.org
Fri Aug 28 16:33:17 CEST 2015


Hello,

I have drawn on the following posting to draw a raster 'under' a set of polygons as shown in the image link below.  The data used is available at the third link (about 650KB).

Posting: http://stackoverflow.com/questions/27062768/how-to-plot-additional-raster-with-spplot

Image: https://dl.dropboxusercontent.com/u/8433654/sp-over-plot.png

Example data: https://dl.dropboxusercontent.com/u/8433654/example.RData

Here is a brief description of each variable plotted.

R is a single layer RasterStack of sea surface temperatures
qa is a SpatialPolygonsDataFrame of fisheries management polygons
spdfbb is also a SpatialPolygonsDataFrame that contains a single polygon (created from the extent of qa)

sp::spplot(spdfbb, 
   colorkey = FALSE,
   sp.layout = list(b = list('sp.polygons', qa, col = 'grey', first = FALSE))) + 
   latticeExtra::as.layer(spplot(R), under = TRUE)

Is it possible add a colorbar for the raster, R, as it might appear if I called...

spplot(R)

Session info is below my signature.

Thanks!
Ben

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.5 (Mavericks)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] latticeExtra_0.6-26 lattice_0.20-33     rgeos_0.3-8         obpgcrawler_0.1     ecocastmap_0.1     
 [6] RColorBrewer_1.1-2  ggplot2_1.0.1       rgdal_0.9-3         spnc_0.1            raster_2.4-15      
[11] sp_1.1-1           

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.0      magrittr_1.5     MASS_7.3-43      munsell_0.4.2    colorspace_1.2-6 R6_2.1.1        
 [7] stringr_1.0.0    httr_1.0.0       plyr_1.8.3       tools_3.2.2      grid_3.2.2       gtable_0.1.2    
[13] digest_0.6.8     reshape2_1.4.1   ncdf4_1.13       curl_0.9.3       stringi_0.5-5    scales_0.2.5    
[19] XML_3.98-1.3     proto_0.3-10 


More information about the R-sig-Geo mailing list