Skip to content
Prev 5919 / 29559 Next

Vedr.: Re: plotting a polygon with holes

That works like a charm:
Thank you very much, once again.

Bjarke Christensen.



                                                                           
             Roger Bivand                                                  
             <Roger.Bivand at nhh                                             
             .no>                                                      Til 
                                       Bjarke Christensen                  
             11-06-2009 15:21          <Bjarke.Christensen at sydbank.dk>     
                                                                        cc 
                                       r-sig-geo at stat.math.ethz.ch         
              Besvar venligst                                         Emne 
                    til                Re: [R-sig-Geo] plotting a polygon  
             Roger.Bivand at nhh.         with holes                          
                    no
On Thu, 11 Jun 2009, Bjarke Christensen wrote:

            
blue
As you observe, the approach you are taking does not work, as the R
graphics devices work by over-painting in layers. To see the image, it has
to be painted after the enclosing rectangle. Holes are painted by
re-painting the hole in a chosen background colour, which by default is
"transparent", so you just get lots of blue.

Why not do something like

o <- overlay(myDEM, islands)

(untried) to get just the raster cells within the island polygons as a
SpatialPixelsDataFrame object and image() that, possibly setting the
background to a suitable colour (NAs will get transparent by default).
This works with the graphics system, rather than trying to work round it -
it doesn't "remember" that there is anything on the canvas that should be
protected from overpainting, so it is safer just to paint what needs
painting. I can also imagine painting first with reduced opacity (or
intensity) in a different palette, then overpainting just the islands with
full intensity in the target palette, which might be more visually
pleasing than just flat blue sea.

Hope this helps,

Roger


--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no