[R-sig-Geo] maptools

Roger Bivand Roger.Bivand at nhh.no
Thu Sep 29 12:49:01 CEST 2005


On Thu, 29 Sep 2005, Joao Pedro Azevedo wrote:

> I'm having trouble posting the message below on R-geo mailing list, and
> maybe you could easily help me.
> 
> 
> Hello all,
> I've been using the syntax below to plot a few maps with R, however I would
> like to know if would be possible to omit the box with y and x coordinates.
> I've gone through the online help and did not manage to find anything that
> seemed to do the job.
> Many help will be more than welcomed!
> Cheers,
> JP
> 
> 
> 
> library(maptools)
> x <- read.shape(system.file("shapes/sids.shp", package="maptools")[1])
> plot(x)
> nParts <- sapply(x$Shapes, function(x) attr(x, "nPart"))
> table(nParts)
> cols <- c("azure", "blue", "orange")
> fgs <- cols[nParts]
> plot(x, fg=fgs)
> res <- plot(x, auxvar=x$att.data$BIR74)
> str(res)
> res <- plot(x, auxvar=x$att.data$BIR74, type="e",ol = "transparent",
> prbg=NULL)
> str(res)
> 

Just using the "Map" created by read.shape(), the plot.Map() function 
allows but wronly passes through arguments to plot:

> library(maptools)
> x <- read.shape(system.file("shapes/sids.shp", package="maptools")[1])
Shapefile type: Polygon, (5), # of Shapes: 100
> plot(x, axes=FALSE, ann=FALSE)
There were 50 or more warnings (use warnings() to see the first 50)

Using the newer and much better supported mechanisms in the sp package 
(note that maptools depends on sp from version 0.5-*):

> xsp <- readShapePoly(system.file("shapes/sids.shp", 
+ package="maptools")[1], proj4string=CRS("+proj=longlat"))
> plot(xsp)
> nParts <- getSpPnParts(xsp)
> cols <- c("azure", "blue", "orange")
> fgs <- cols[nParts]
> plot(xsp, col=fgs)

and even:

> plot(xsp, col=fgs, axes=TRUE)

That is, the default for plot of Spatial* objects defined in sp is not to 
plot axes or annotate. We are encouraging users to try out the sp class 
objects rather than the legacy ones.

Best wishes,

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




More information about the R-sig-Geo mailing list