On Tue, 26 Aug 2008, Michael Friendly wrote:

Edzer Pebesma wrote:


 Michael Friendly wrote:
>  Two short questions about working with maps:
> > 1. I'm reading a shapefile with character labels for the regions (FSA). > I can add the labels using plot(), > but when I try the same thing using spplot(), the labels are in the > wrong positions -- they all seem to be
>  shrunk somewhat in toward the center of the map.  What am I doing wrong?
> > # this doesn't work-- labels in wrong position
>  spplot(toronto,"FSA_NAME", colorkey=FALSE)
>  text(coordinates(toronto), labels=as.character(toronto$FSA), cex=0.4)
 Right: text() works with base graphics, not with lattice on which spplot
 is built.

 Something like this should work:
 spplot(toronto,"FSA_NAME", colorkey=FALSE,
    sp.layout = list("sp.text", coordinates(toronto),
 as.character(toronto$FSA), cex=0.4))

Great!  Now I also know where to look to generalize this.
> > 2. I have a bunch of attribute variables for the geographic regions, all > on different scales. Id like to > produce a set of comparative maps in the same figure (say with spplot()) > with each attribute shaded > by its quantiles, e.g., 5 classes each. Do I have to precompute these > first, or is there something I can do in the call > to spplot() to have this done, using the variables in the > SpatialPolygonsDataFrame?
 What exactly did you mean by "all on different scales"? They have
 different polygon structures?
No - some of the attribute values are percents, some are quantitative & positively skewed, like Income. If I do

spplot(toronto, c("Household.Income","Unemployed","University"))
a single scale is applied to all three, so the two % variables are shaded uniformly in the lowest range. What I'd like is to apply a function to take each of these and recode into quantiles for that variable.

After a little digging around, it looks as though the plot() method for trellis objects (pp. 202-206 in the Lattice book) provides a way to generate a single graphic from multiple calls to spplot, something like:

p1 <- spplot(toronto, c("Household.Income"))
p2 <- spplot(toronto, c("Unemployed"))
p3 <- spplot(toronto, c("University"))
plot(p1, split=c(1,1,2,2), more=TRUE)
plot(p2, split=c(1,2,2,2), more=TRUE)
plot(p3, split=c(2,1,2,2), more=FALSE)

using at=, col.regions=, main=, etc. in each of the spplot calls as appropriate for the selected variables. With the same col.regions= and at= based on quantiles (perhaps floor() for the first and ceiling() for the last), this should be pretty close visually, but with a key for each variable.


It's partly that my data variables are now in the map object and, from the help, I only know how to refer to zcol= names of these, rather than some transformations on the underlying data.

The alternative might be to assign new derived variables to the Spatial*DatatFrame object, which for all intents and purposes "is" a data frame, and spplot() them.

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

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to