Matt Bannert
Matt Bannert

Reputation: 28264

How to use regions' names as labels in spatial Data?

I use the following code to visualize some SpatialPolygonsDataFrame with ggplot2:

require(shapefiles) 
require(sp)

xx <- readShapeSpatial(system.file("shapes/sids.shp", package="maptools")[1],
                   IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))


xx.ff <- fortify(xx,region="NAME")

x <- ggplot(xx.ff) +
aes(long,lat, fill = id) +
geom_polygon()

to end up with:

enter image description here

Assume that I am using fill to represent something else, like regional theft rate. Thus I want to label those regions with their names. is there a way to write the regions name right onto the map into the corresponding region, e.g. I want to write Halifax right onto the region.

Upvotes: 1

Views: 1370

Answers (1)

Related Questions