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

2015-09-02 Thread Edzer Pebesma


On 09/02/2015 03:07 PM, Ben Tupper wrote:
> I can see in the source code, spplot.R, that SpatialPolygonsDataFrame and 
> SpatialLinesDataFrame are handled by levelplot; thanks for pointing that out. 
> That SpatialPointsDataFrame is handled by xyplot gives me pause now.  In 
> fact, if I think about it it confuses me, so I best not think about that 
> first thing in the morning!

xyplot has the concept of one symbol per observation, with a colour, a
size, a symbol type. That is how I thought of plots of
SpatialPointsDataFrame at the time  I wrote it.
-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi),  University of Münster,
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software:   http://www.jstatsoft.org/
Computers & Geosciences:   http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info



signature.asc
Description: OpenPGP digital signature
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2015-09-02 Thread Ben Tupper
Hi,

On Aug 30, 2015, at 6:37 AM, Edzer Pebesma  
wrote:

> On 08/29/2015 10:55 AM, Tim Appelhans wrote:
>> 
>> I am not sure why SpatialPolygons* objects get rendered via levelplot.
> 
> because levelplot has the understanding of plotting something in 2D,
> using colours according to the continuous variation of a third variable.

Thanks to you and Tim for the clarifications.  

I can see in the source code, spplot.R, that SpatialPolygonsDataFrame and 
SpatialLinesDataFrame are handled by levelplot; thanks for pointing that out. 
That SpatialPointsDataFrame is handled by xyplot gives me pause now.  In fact, 
if I think about it it confuses me, so I best not think about that first thing 
in the morning!

I agree with Tim that starting with the raster first and then adding the 
polygons with latticeExtra::as.layer() is more intuitive. 

Thanks again,
Ben

> -- 
> Edzer Pebesma
> Institute for Geoinformatics (ifgi),  University of Münster,
> Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
> Journal of Statistical Software:   http://www.jstatsoft.org/
> Computers & Geosciences:   http://elsevier.com/locate/cageo/
> Spatial Statistics Society http://www.spatialstatistics.info
> 
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

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

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2015-08-30 Thread Edzer Pebesma


On 08/29/2015 10:55 AM, Tim Appelhans wrote:
 
 I am not sure why SpatialPolygons* objects get rendered via levelplot.

because levelplot has the understanding of plotting something in 2D,
using colours according to the continuous variation of a third variable.
-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi),  University of Münster,
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software:   http://www.jstatsoft.org/
Computers  Geosciences:   http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info



signature.asc
Description: OpenPGP digital signature
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2015-08-29 Thread Tim Appelhans

Ben,
as a follow up, it also works the other way round, which is more intuative:

pols - spplot(spdfbb,
   colorkey = FALSE,
   sp.layout = list(b = list('sp.polygons', qa, col = 
'grey', first = FALSE)))


rst - spplot(R)

combo - rst + as.layer(pols)
combo

I am not sure why SpatialPolygons* objects get rendered via levelplot.
In general, the crux with lattice/latticeExtra is that all layers 
essentially get amalgamated into one list object and hence the style 
settings for the plot are taken from the first object (rst). So if you 
were to draw pols first, the relevant colorkey specification would be 
taken from pols:


pols2 - spplot(spdfbb,
colorkey = list(col = heat.colors(101), width = 1,
at = seq(0, 30, length.out = 100),
space = top),
sp.layout = list(b = list('sp.polygons', qa, col = 
'grey', first = FALSE)))


pols2

combo2 - pols2 + as.layer(rst, under = TRUE) #colorkey now taken from pols2
combo2

combo3 - rst + pols2 #same as above as colorkey is taken from rst
combo3

Best
Tim




On 29.08.2015 02:32, Ben Tupper wrote:

That works like a charm.

It's sort of non-intuitive that I would use the colorkey argument for the plot 
of the polygons since color key is documented for levelplot.  In my naive view 
I would looked to xyplot when plotting polygons. I'm still in the grope and 
thrash stage with lattice/spplot (and occasionally enjoying it.)

Thanks so much!

Ben

On Aug 28, 2015, at 10:51 AM, Tim Appelhans tim.appelh...@gmail.com wrote:


Ben,
you could specify the colorkey manually in the spplot call for spdfbb:

sp::spplot(spdfbb,
   colorkey = list(col = bpy.colors(101), width = 1,
   at = seq(0, 30, length.out = 100),
   space = top),
   sp.layout = list(b = list('sp.polygons', qa, col = 'grey', first = 
FALSE))) +
  latticeExtra::as.layer(spplot(R, at = seq(0, 30, length.out = 100)), under = 
TRUE)


You simply need to make sure to pass the same specs to the spplot call to R.

HTH
Tim

On 28.08.2015 16:33, Ben Tupper wrote:

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.0httr_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-5scales_0.2.5
[19] XML_3.98-1.3 proto_0.3-10
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

--
#
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

http://environmentalinformatics-marburg.de/

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



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


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

2015-08-28 Thread Tim Appelhans

Ben,
you could specify the colorkey manually in the spplot call for spdfbb:

sp::spplot(spdfbb,
   colorkey = list(col = bpy.colors(101), width = 1,
   at = seq(0, 30, length.out = 100),
   space = top),
   sp.layout = list(b = list('sp.polygons', qa, col = 'grey', 
first = FALSE))) +
  latticeExtra::as.layer(spplot(R, at = seq(0, 30, length.out = 100)), 
under = TRUE)



You simply need to make sure to pass the same specs to the spplot call to R.

HTH
Tim

On 28.08.2015 16:33, Ben Tupper wrote:

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.0httr_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-5scales_0.2.5
[19] XML_3.98-1.3 proto_0.3-10
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
#
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

http://environmentalinformatics-marburg.de/

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2015-08-28 Thread Ben Tupper
Hi,

Perfect!  I wouldn't have gotten there in a hundred years.  

Thanks,
Ben

On Aug 28, 2015, at 10:51 AM, Tim Appelhans tim.appelh...@gmail.com wrote:

 Ben,
 you could specify the colorkey manually in the spplot call for spdfbb:
 
 sp::spplot(spdfbb,
   colorkey = list(col = bpy.colors(101), width = 1,
   at = seq(0, 30, length.out = 100),
   space = top),
   sp.layout = list(b = list('sp.polygons', qa, col = 'grey', first = 
 FALSE))) +
  latticeExtra::as.layer(spplot(R, at = seq(0, 30, length.out = 100)), under = 
 TRUE)
 
 
 You simply need to make sure to pass the same specs to the spplot call to R.
 
 HTH
 Tim
 
 On 28.08.2015 16:33, Ben Tupper wrote:
 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.0httr_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-5scales_0.2.5
 [19] XML_3.98-1.3 proto_0.3-10
 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo
 
 -- 
 #
 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
 
 http://environmentalinformatics-marburg.de/
 
 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo



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

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2015-08-28 Thread Ben Tupper
That works like a charm.

It's sort of non-intuitive that I would use the colorkey argument for the plot 
of the polygons since color key is documented for levelplot.  In my naive view 
I would looked to xyplot when plotting polygons. I'm still in the grope and 
thrash stage with lattice/spplot (and occasionally enjoying it.)

Thanks so much!

Ben

On Aug 28, 2015, at 10:51 AM, Tim Appelhans tim.appelh...@gmail.com wrote:

 Ben,
 you could specify the colorkey manually in the spplot call for spdfbb:
 
 sp::spplot(spdfbb,
   colorkey = list(col = bpy.colors(101), width = 1,
   at = seq(0, 30, length.out = 100),
   space = top),
   sp.layout = list(b = list('sp.polygons', qa, col = 'grey', first = 
 FALSE))) +
  latticeExtra::as.layer(spplot(R, at = seq(0, 30, length.out = 100)), under = 
 TRUE)
 
 
 You simply need to make sure to pass the same specs to the spplot call to R.
 
 HTH
 Tim
 
 On 28.08.2015 16:33, Ben Tupper wrote:
 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.0httr_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-5scales_0.2.5
 [19] XML_3.98-1.3 proto_0.3-10
 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo
 
 -- 
 #
 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
 
 http://environmentalinformatics-marburg.de/
 
 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo



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

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo