[R] trouble with maps

Roger Bivand Roger.Bivand at nhh.no
Wed Jul 23 21:09:05 CEST 2003

On Wed, 23 Jul 2003, Deborah Swayne wrote:

> Has anyone else seen this behavior from the "maps" package?
> map('state', fill=TRUE)
> results in a lively mix of overlapping polygons inside a
> map of the US, but they have no obvious relationship to
> state boundaries.  (See attached jpeg.)

Yes, this replicates. I think the trouble is in the part of map() where it 
makes a polygon of the lines:

    if (fill) {
        gonsize <- line$size
        color <- rep(color, length = length(gonsize))
        keep <- !is.na(color)
        coord[c("x", "y")] <- makepoly(coord, gonsize, keep)
        color <- color[keep]

and I think makepoly needs gon, not gonsize, as an argument, to stitch the 
boundary lines together in the correct order - the "interesting" effect 
seems to come from some lines not being reversed. Unfortunately, I don't 
have archival copies of earlier map() functions to check this - it could 
also be in mapgetl():

        if (fill) 
            coord <- mapgetl(database, line$number, xlim, ylim)

although this is less likely, because the same function is used to 
retrieve the same data when fill=FALSE too. Something has got lost in 
building the polygons, it seems! As far as I can establish, fill=TRUE did 
work in earlier versions.

> p <- map('state', region=c('penn'), resolution=0)
> plot(p, type="l")

gives the boundaries in both cases,

> pf <- map('state', region=c('penn'), fill=TRUE, resolution=0)

gives black/white "interesting" polygons, and

> plot(pf, type="l")

draws the boundary lines with wrong links to next line segents.


Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no

More information about the R-help mailing list