[R-sig-Geo] clipping in maptools

Roger Bivand Roger.Bivand at nhh.no
Fri Sep 30 23:38:39 CEST 2005


On Fri, 30 Sep 2005, Sebastian Luque wrote:

> Hi,
> 
> I'm using package maptools for reading and plotting shape files, and am
> looking for a way to "clip" the shapes for plotting only.  More
> precisely, I need to plot only a certain region of the original shape file
> by providing the N, S, E, and W latitudes and longitudes that bound the
> region.  If this is not possible in maptools, can somebody please suggest
> a package to do this sort of manipulation?
> 

> library(maptools)
Loading required package: foreign
Loading required package: sp
> xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], 
+ proj4string=CRS("+proj=longlat +ellps=clrk66"))
> plot(xx, border="blue", axes=TRUE, las=1)
> plot(xx, border="blue", axes=TRUE, las=1, xlim=c(-82,-78), xaxs="i")

Using the plot method for sp class SpatialPolygons, the xlim= and ylim=
arguments do what you want. They do in plot.polylist() too, but in
plot.Map() you get warnings when the arguments are passed to plotting
functions that don't know about them.

If you have an updated maptools package - which depends on the sp package 
being installed too, just use xlim= and ylim= to define your plot area, or 
with older maptools versions (< 0.5) use plot.polylist(). Both the plot 
method for Spatial Polygons and plot.polylist respect the xaxs= and yaxs= 
arguments (setting them to "i" bounds the axes tightly to the *lim= 
values, the default value of "r" "grows" the axes 4% at each end, see ?par 
for details).

> 
> Thanks in advance,
> 
> 

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




More information about the R-sig-Geo mailing list