[R] filled maps

Ray Brownrigg ray at mcs.vuw.ac.nz
Tue Feb 3 21:49:01 CET 2004


> Date: Tue, 3 Feb 2004 11:34:06 +0100 (CET)
> From: Roger Bivand <Roger.Bivand at nhh.no>
> 
> On Tue, 3 Feb 2004, Janus Larsen wrote:
> 
> > Hi R-Help,
> > 
> > I would like to make filled contour maps of ocean data overlaid by
> > costlines from the map package.
> > I can draw the filled contours and the coastlines om the same plot, but
> > the filled contour also covers part of the land. To get rid of that I
> > tried to draw a filled coastline map on top of the filled contour, but
> > the filled map only draws the closed contours - so most of the land is
> > missing.
> > Example:
> > map("worldHires",xlim=c(0,15),ylim=c(50,60)) #Draw relevant region
> > (North Sea and Denmark waters)
> > map("worldHires",xlim=c(0,15),ylim=c(50,60),fill=TRUE) # This only draws
> > Denmark and Holland (Sweden, uk, Germany etc. disappears because they
> > are not closed polygons).
> 
> Looks as though you can use the regions= argument:
> 
> > res <- map("worldHires",xlim=c(0,15),ylim=c(50,60), plot=FALSE, 
> + namesonly=TRUE)
> > map("worldHires",xlim=c(0,15),ylim=c(50,60))
> > map("worldHires",regions=res, fill=TRUE, add=TRUE)
> 
Thanks Roger, I hadn't got around to figuring out that workaround.
Certainly the mapgetg code explicitly excludes incomplete polygons if 
fill=TRUE, but since the polygon() function is happy to clip what it is
filling, your workaround takes advantage of that.

I'll have a look at getting mapgetg to do this itself - it would have
to always provide complete polygons if fill=TRUE instead of just
'visible' polylines.

> fixes it for me. Curiously, the longitudes add 2.5 degrees on each side.
> 
Actually this is to preserve aspect ratio.  An earlier version of the
maps package adjusted the shape of the figure to conform to both aspect
ratio and imposed limits.  I didn't deliberately change this, but I
think I know why it has happened, so I'll look at this also.

Ray Brownrigg




More information about the R-help mailing list