
I had some fun today getting the location of each county seat in California. You can see the code here if you’re curious: https://github.com/fadend/county_seat_coords.
The data are pulled from Wikipedia’s List of counties in California. I plotted them going through the tutorial here: https://eriqande.github.io/rep-res-eeb-2017/map-making-in-R.html. (Very nice!) Here’s my ugly R code for doing that, shamelessly stealing some of the code from the course:
library(ggplot2)
library(ggrepel)
# Note: map_data is provided by ggplot2.
states <- map_data("state")
counties <- map_data("county")
ca <- states[states$region == "california", ]
ca_counties <- counties[counties$region == "california", ]
seats <- read.csv("~/projects/seatenv/county_seats.csv", stringsAsFactors=FALSE)
ca_base <- ggplot(data=ca, mapping=aes(x=long, y=lat, group=group)) +
coord_quickmap() +
geom_polygon(color="black", fill="gray")
ca_base + theme_void() +
geom_polygon(data=ca_counties, fill=NA, color="white") +
geom_point(data=seats, aes(x=lng, y=lat, group=county)) +
geom_text_repel(data=seats, aes(x=lng, y=lat, label=county_seat, group=county)) +
geom_polygon(color="black", fill=NA)
ggrepel is really nice! I was having lots of problems with overplotting of city names, but it fixed it beautifully with no more fiddling.
However, though I’m happy with how the plot turned out, it also seems to reveal a potential data issue. Crescent City seems to be sitting in the ocean.
However, putting the lat-lng we’ve extracted for Crescent City, 41.756111, -124.201667, into Open Street Maps, they seem to be solidly on land:

Is the boundary for Del Norte County a little off in the data from map_data("county")
?
Leave a Reply