[R-sig-Geo] spplot: labels on maps / variables on different scales

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Aug 26 14:45:21 CEST 2008



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?
>
> library(maptools)
> # using readShapeSpatial
> ontario 
> <-readShapeSpatial("ForwardSortationAreas_JUL07_ON_region.shp", 
> IDvar="FSA", proj4string=CRS("+proj=longlat +datum=NAD83") )
> toronto <- ontario[ontario$F=="M",]
> summary(toronto)
> # this works OK
> plot(toronto)
> text(coordinates(toronto), labels=as.character(toronto$FSA), cex=0.4)
>
> # 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))

>
> 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?
--
Edzer
>
> > toronto <- spCbind(toronto, crimeTO)
> > summary(toronto)
> Object of class SpatialPolygonsDataFrame
> Coordinates:
>         min       max
> r1 -79.63925 -79.11484
> r2  43.58103  43.85547
> Is projected: FALSE
> proj4string : [+proj=longlat +datum=NAD83]
> Data attributes:
>      FSA            FSA_NAME  F        PR               Area      
> Jail.Cost           Rank     M1B    : 1   TORONTO    :48   K:  0   
> 35:102   Toronto    :39   Min.   :     0   Min.   :  6.0 M1C    : 1   
> NORTH YORK :22   L:  0            North York :24   1st Qu.:  3205   
> 1st Qu.:126.8 M1E    : 1   SCARBOROUGH:17   M:102            
> Scarborough:17   Median : 42249   Median :296.5 M1G    : 1   
> ETOBICOKE  :12   N:  0            Etobicoke  :12   Mean   : 84991   
> Mean   :259.7 M1H    : 1   EAST YORK  : 3   P:  0            East 
> York  : 5   3rd Qu.:139404   3rd Qu.:406.0 M1J    : 1   ACTON      : 
> 0                    York       : 5   Max.   :506339   Max.   :413.0 
> (Other):96   (Other)    : 0                    (Other)    : 
> 0                                     Inmates       Inmates.per.10K 
> Days.Sentenced     Population    Household.Income
> Min.   : 0.000   Min.   :0.000   Min.   :   0.0   Min.   :    0   
> Min.   : 35129 1st Qu.: 1.000   1st Qu.:0.325   1st Qu.:  30.0   1st 
> Qu.:15857   1st Qu.: 48438 Median : 3.000   Median :1.000   Median : 
> 395.5   Median :23564   Median : 58015 Mean   : 3.559   Mean   
> :1.180   Mean   : 795.6   Mean   :25161   Mean   : 62123 3rd Qu.: 
> 5.000   3rd Qu.:1.800   3rd Qu.:1305.0   3rd Qu.:34878   3rd Qu.: 
> 66259 Max.   :15.000   Max.   :4.300   Max.   :4740.0   Max.   
> :66878   Max.   :127669 
>                                                                   
> NA's   :     5   Low.Income      Unemployed      University     
> Female.Homes   Public.Housing
> Min.   : 6.00   Min.   :2.000   Min.   : 8.00   Min.   : 8.00   Min.   
> :   2 1st Qu.:15.00   1st Qu.:4.000   1st Qu.:20.00   1st Qu.:13.00   
> 1st Qu.: 234 Median :20.00   Median :5.000   Median :28.00   Median 
> :16.00   Median : 685 Mean   :20.05   Mean   :5.412   Mean   :31.31   
> Mean   :16.16   Mean   : 995 3rd Qu.:25.00   3rd Qu.:7.000   3rd 
> Qu.:45.00   3rd Qu.:19.00   3rd Qu.:1276 Max.   :41.00   Max.   
> :9.000   Max.   :64.00   Max.   :30.00   Max.   :9289 NA's   : 5.00   
> NA's   :5.000   NA's   : 5.00   NA's   : 5.00   NA's   :  27 >
>

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster,
Weseler Straße 253, 48151 Münster, Germany.  Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de/




More information about the R-sig-Geo mailing list