Skip to content
Prev 1735 / 29559 Next

Map2points() substitute for class "map"

On Mon, 12 Feb 2007, Fernando Mayer wrote:

            
Map2points() is a function returning a matrix of coordinates, from a 
point-type Map object, for the centres of the proportional symbols. You 
will not get anywhere using an object of class "map", because it is either 
a collection of polygon boundaries or a collection of lines, and they are 
not associated with any data. If you have "map" polygons, then you need 
some central point to pass to ProportionalSymbolMap(). So you'll need to 
find those points. The SpatialPolygons objects in the sp package define 
centroids by default.

If you comment out the lines:

#  if(missing(map)) stop("map object is missing.")
#  if(!inherits(map, "Map")) stop("Map.obj must be of class Map")
#  if(missing(variable)) stop("variable to be plot is missing")

in ProportionalSymbolMap(), and rename the map argument as verts, you can 
pass the coordinates in:

library(maps)
map <- map("county", "illinois", fill=TRUE, col="transparent", plot=FALSE)
library(maptools)
str(map)
ID <- substring(map$names, 10)
ill <- map2SpatialPolygons(map, ID, proj4string=CRS("+proj=longlat"))
plot(ill, axes=TRUE)
x <- runif(102)
ProportionalSymbolMap_rev(coordinates(ill), x, max.size=0.3)

Note that you have to be careful with polygon IDs, and need to match them 
with the data remembering that the order is very likely to differ.

Would it be sensible to include ProportionalSymbolMap() in maptools? In 
fact, it is the legend that is the tough problem, so in fact using the 
bubble-plot method in sp may be an easier way forward:

SPDF <- SpatialPointsDataFrame(coordinates(ill), data=data.frame(x=x), 
  proj4string=CRS("+proj=longlat"))
bubble(SPDF, "x", axes=TRUE)

There does not seem to be an easy way to plot the polygon borders as a 
background in the bubble method, which uses lattice graphics.

The use of sp class objects tends to make questions like this easier to 
handle.

Roger