[R-sig-Geo] Pretty readable labels with spplot
Julien Barnier
jbarnier at ens-lsh.fr
Mon Jun 2 16:45:24 CEST 2008
Hi,
I keep using spplot to draw some simple maps, but I wonder if someone
has got a good method to draw nice and readable labels above a polygon
map ? More precisely, I wonder if there is a way to draw the labels in
black with a small white border around them in order to keep them
readable over a dark color.
I tried by writing two labels layout, one white and one black, either
by putting the first in bold face or by moving it a bit, but I don't
find the result very good. Here is an example :
library(sp)
library(maptools)
library(RColorBrewer)
nc <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
labels <- as.character(nc$NAME)
locs.labels <- getSpPPolygonsLabptSlots(nc)
nc.labels <- maptools::pointLabel(x=locs.labels[,1],y=locs.labels[,2],labels=labels,doPlot=FALSE)
nc.labels.white.panel <- list("panel.text",nc.labels$x-0.005,nc.labels$y-0.005,labels=labels,col="white",cex=0.5)
nc.labels.panel <- list("panel.text",nc.labels$x,nc.labels$y,labels=labels,col="black",cex=0.5)
spplot(nc, 'AREA', sp.layout=list(nc.labels.white.panel,nc.labels.panel), col.regions=brewer.pal(7, "Reds"), cuts=6)
Thanks in advance for any advice !
Sincerely,
Julien
--
Julien Barnier
Groupe de recherche sur la socialisation
ENS-LSH - Lyon, France
More information about the R-sig-Geo
mailing list