On Mon, 12 Feb 2007, Fernando Mayer wrote:

> Hi,
> 
> following Tanimura et al. 2006 (Proportional Symbol Mapping in R) [1], 
> I'm trying to implement the ProportionalSymbolMap function for maps of 
> class "map" (produced by the maps package), instead of maps of class 
> "Map" (imported from a GIS polygon vector file). That function uses 
> the Map2points() function to (as far as I could understand) extract 
> the points (i.e. map boundaries) from a "Map" object to a n x 2 
> matrix, as in
> 
>  > verts <- Map2points(map)[order(variable, decreasing = T),]
> 
> What I tried to do to substitute this function was
> 
>  > verts <- matrix(c(map$x,map$y),ncol=2)[order(variable,
>       decreasing = T),]
> 
> where map is an object of class "map". But, that doesn't work. As I 
> have no experience with shapefiles, I'm restricted to know what 
> exactly Map2points() does and if there is some other function that can 
> do the same thing for a "map" object.

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

> 
> BTW, if trying to implement this function (ProportionalSymbolMap) for 
> a "map" object (instead of a "Map") is not a good idea (because all 
> the rest of the function), please let me know. I think (on my limited 
> knowledge on this) that with same adjustments it may be possible.
> 
> [1] http://www.jstatsoft.org/v15/i05/v15i05.pdf
> 
> Thanks for any hint,
> 

-- 
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: [EMAIL PROTECTED]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to