I think I must be overlooking something very simple here.
I'd like to apply labels to a set of polygons. Specifically, I'm trying to place labels on a handful of California congressional districts.
I begin by getting the basemap (socal) and overlaying data from my district SPDF (congress) over it:
socal <- get_map(location = "Riverside, USA", zoom = 8, source = "google",
maptype = "roadmap")
somap <- ggmap(socal) +
geom_polygon(data = congress,
aes(x = long, y = lat, group = group),
fill = "#F17521", color = "#1F77B4", alpha = .6)
So far, so good.
But then I'd like to label each polygon, so I create a new variable:
congress@data$DistrictLabel <- paste("CD", congress@data$DISTRICT, sep = "")
And when I try to add this to my map...
somap + geom_text(data = congress, aes(x = long, y = lat, label = DistrictLabel))
I get the following error:
Error in eval(expr, envir, enclos) : object 'DistrictLabel' not found
I know I'm overlooking something obvious, but I can't figure out what it is! Any help would be much appreciated.
Thanks!