[R-sig-Geo] how to avoid manual trimming of polygons from map() ?

Stephen Tucker brown_emu at yahoo.com
Fri Mar 13 08:42:02 CET 2009


Hello all,

I was trying to plot a stereographic projection (centered around Bering Strait)  using map() but am having to manually trim the polygons:

## choose limits
xlim <- c(110,290); ylim <- c(40,90)

## plot - doesn't look right
map("world2",projection="stereographic",xlim=xlim,ylim=ylim)

## extract polygons and trim manually
mp <- map("world2",xlim=xlim,ylim=ylim,plot=FALSE)
w <- which(mp$x < min(xlim) | mp$x > max(xlim))
mp$x <- mp$x[-w]; mp$y <- mp$y[-w]

## replot
map(mp,projection="stereographic",xlim=xlim,ylim=ylim,border=0)
map.grid(c(xlim,ylim),xpd=TRUE,col=8,lab=FALSE)

###

This also leaves significant whitespace around the actual coastlines (in the plotting region, as observed when box() is invoked after drawing the map)... I wonder if there is a way to trim points and fill the plotting region?

Thanks much!

Stephen



More information about the R-sig-Geo mailing list