[R-sig-Geo] spplot with quantitative variable

Matthieu Stigler matthieu.stigler at gmail.com
Thu Aug 13 11:03:18 CEST 2009


Hi

I'm new to sptial analysis and just dicovers so I have a really basic
question. I could unfortunately not find the answer on  in the tuto,
help files or springer book (tough it is sure there :-(). So sorry if
the answer is trivila but this would help me a lot!

I have a an object say TRY of class "SpatialPolygonsDataFrame"
representing a country and its subareas (26). First question, is there
a generic function to access the name of the subdivisions?
I used the workaround: as.data.frame(TRY)[,"NAME_1"] is there
something more elegant? How to extract the values in general?
TRY[,"NAME_1"] prints a lot of information beside the series I want.

My problem actually concerns to add a new series (say population) to
this dataset, and to plot it...

To add the series, I did:
data$new<-rnorm(100)

is that the right manner?

Then I tried to plot it using spplot() but I hvae the following
problem: the colors are just sorted following the order in which the
values appear in the series (so the first subdivion with name A...
with low pop can have same color as subdivion B with high color). So
the data is not sorted correspondly and the colors are totally messed
up. I just want to have the colors "increasing " with the population.
Furterhmore, my scale just shows the individual values for each
subdivision...

What shoulk I use? Define myself colors palette as in the springer
book at section 3,4? Do I do something wrong when adding the variable?
I don't understand why I dont get the same result as the example in
the demo(gallery):

library(sp); library(lattice) # required for trellis.par.set():
 trellis.par.set(sp.theme()) # sets color ramp to bpy.colors()
 library(maptools)
 nc <- readShapePoly(system.file("shapes/sids.shp",
package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
spplot(nc, "SID79", names.attr = "1979")

here the scale does not give the individual values as in my case. Are
those object "SID79" and the series I entered so different? I can I
caompre them?

Thanks a lot!!

Matthieu Stigler



More information about the R-sig-Geo mailing list