[R] control margin when plotting polygons?

Roger Bivand Roger.Bivand at nhh.no
Sat May 12 11:30:24 CEST 2007

On Fri, 11 May 2007, Shengde Liang wrote:

> Hello everyone,
> I have some difficulties on controling the margin of a plot.
> For example, the following code from the help of maptools:
> library(maptools)
> xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], 
> IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
> plot(xx, border="blue", axes=TRUE, las=1)
> There is a lot of white margin on the bottom and top of the plot and I 
> want to get rid of it. I used option "usr", but it does not make any 
> change.
> plot(xx, border="blue", axes=TRUE, las=1,usr=c(-85,-75,33,39))
> par(usr=c(-85,-75,33,39))
> plot(xx,border="blue",axes=T,las=1)
> Option "ylim" does not work either.

This plot method is more complicated than you can see for geographical 
coordinates, because the y axis is streched. But the real cause of your 
problem is the shape of the plot device. If you compare the output of:

png("default_size.png", pointsize=8)
plot(xx, border="blue", axes=TRUE, las=1)
png("portrait_size.png", width=300, height=480, pointsize=8)
plot(xx, border="blue", axes=TRUE, las=1)
png("landscape_size.png", width=480, height=300, pointsize=8)
plot(xx, border="blue", axes=TRUE, las=1)

you can see that the amount of the plotting area covered by the map can be 
controlled to reduce the white space.

You can also use par(mar=c()) to remove margins, but then possibly without
the axes, or at least watching the effects of las=. The GE_SpatialGrid()  
function also sets up cropping sizes for export of maps in geographical
coordinates as image overlays for Google Earth, and may contain some

> Anyone has any idea how to do it?

The answers vary a great deal depending on needs, and are seldom 
completely general. For publication, editing externally may be an option.


> Thanks a lot.
> Best,
> Shengde Liang
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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-help mailing list