[R-sig-Geo] Map labels
Roger Bivand
Roger.Bivand at nhh.no
Mon Nov 23 15:12:42 CET 2009
On Mon, 23 Nov 2009, tom sgouros wrote:
>
> Hello all:
>
> Thanks to all your earlier help, I'm now using spplot to generate a map
> of about 400 polygons representing about 40 different towns. In
> addition to being able to color the polygons, I would like to label the
> plots with a number or the town name.
>
> Being near the water, there are lots of islands, so each town is
> represented by a bunch of polygons. How do I select only one to be
> labeled, and is there a convention for which one would be the best to
> use? I see the labpt slot, in my SpatialPolygonsDataFrame object, but I
> don't see a mostAppropriateLabpt or primaryLabpt or anything like that.
>
> In addition to this, I get no errors when I follow the examples at
> http://r-spatial.sourceforge.net/gallery/ , but I see no labels, either.
>
> This is what I'm doing. Are the colors covering my labels?
>
> spplot(rep.map,zcol="vote02",at=breaks,col.regions=rg,
> layout=list(list("sp.text",getSpPPolygonsLabptSlots(rep.map)[25,],"HERE I AM")))
>
Thanks for the verbatim code. I think that you need to name the argument
sp.layout= rather than layout=. Because of the ... argument list, layout=
doesn't get rejected, but it doesn't get used either. The gallery could do
with refreshing, more recently you could say:
list("sp.text", coordinates(rep.map), row.names(rep.map))
to put the FID value (feature ID) at the centroid of the largest member
polygon (Polygon object) of the entity (Polygons object), for each entity
of the data set.
Use the other arguments to text() as usual to change size, etc.
If overlapping is a problem, use pointLabel() in maptools to provide
alternative placings for the same set of labels and cex= value (with
thanks to Tom Short).
Hope this helps,
Roger
>
> Many thanks,
>
> -tom
>
>
--
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: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list