[R-sig-Geo] spplot and diverging colorbrewer palette

Julien Barnier jbarnier at ens-lsh.fr
Mon Jun 2 15:50:44 CEST 2008


Hi Edzer,

> try the colorkey argument in spplot, it should get passed on to
> spplot, which wraps levelplot.

Thanks for your advice.

In fact it seems that I can achieve something not too far from what I
wanted with the following code :


library(sp)
library(maptools)
library(RColorBrewer)

nc <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
nc at data$AREA2 <- nc at data$AREA - 0.1

at <- pretty(nc at data$AREA2,n=6)
palpos <- brewer.pal(sum(at>0),"Reds")
palneg <- brewer.pal(sum(at<0),"Blues")
palette <- c(rev(palneg),palpos)

spplot(nc, c("AREA2"), col.regions=palette, at=at, scales=list(draw = TRUE))


But I'm really not sure it is the right way to do it...

Thanks again,

Julien

-- 
Julien Barnier
Groupe de recherche sur la socialisation
ENS-LSH - Lyon, France




More information about the R-sig-Geo mailing list