In attempting to plot U.S. Counties from the Census Bureau's 2013 shapefile, the resulting plot has holes/weird fills, especially around counties with discontinuous regions. I think it has something to do with the order of the the points that are plotted, but am not sure how it can be fixed. For example, a plot of Florida, particularly around the Keys produces:
library(ggplot2)
library(dplyr)
library(rgdal)
download.file('http://www2.census.gov/geo/tiger/GENZ2013/cb_2013_us_county_500k.zip',
'county.zip')
unzip('county.zip')
uscounties <- readOGR(.,'cb_2013_us_county_500k' )
uscounties@data$id <- rownames(uscounties@data)
countypoints <- fortify(uscounties, region='id')
countydf <- join(countypoints, uscounties@data, by='id')
ggplot(countydf[countydf$STATEFP=='12' ,])+
aes(long, lat, group=COUNTYNS, fill=STATEFP)+
geom_polygon()+
geom_path(color="black")+
coord_equal()
Here is the resulting plot :
Florida is just an example. Most other states will display similar errors in plotting as well. Any ideas on how to fix?
Why are you setting
group=COUNTYNS
?? Usegroup=id
.You need to take more care when posting a question, so as not to waste peoples' time..
join(...)
is in packageplyr
notdplyr
, anddoesn't work, you need