0

I have a census tiger line file for counties available from the Census website.

I am trying to display this file on a ggmap, but fortify seems to jumble the regions. I can't find anyone else who has run into this error, but I'm certainly not doing anything out of the ordinary...

library(maptools)
library(ggmap)
library(rgeos)

# read shapefile
WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")
Counties <- readShapeSpatial("tl_2013_us_county.shp", proj4string = WGS84)

# limit to Ohio
Counties <- Counties[ Counties$STATEFP == 39, ]

# fortify
Counties.fort <- fortify(Counties, region = "GEOID")

# get base map and plot
OhioMap <- get_map("Ohio", source = 'google', maptype = 'terrain', zoom=7)
ggmap(OhioMap) + geom_polygon(aes(x=long, y=lat), fill = 'grey', alpha=0.4, 
                              color = 'black', data = Counties.fort)

enter image description here

1 Answer 1

2

As it turns out, the solution is to group on the region id. I think I knew this once, but hopefully this can save someone else some Google time.

ggmap(OhioMap) + geom_polygon(aes(x=long, y=lat, group=group), fill = 'grey', alpha=0.4, 
                              color = 'black', data = Counties.fort)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.