
I got the coordinates of the county seats using the utility I previously wrote to get California county seats:
python -m venv seatenv
cd seatenv
bin/pip3 install git+https://github.com/fadend/county_seat_coords
bin/python -m county_seat_coords.fetch_county_seat_coords \
--county_list_wiki_url=https://en.wikipedia.org/wiki/List_of_counties_in_Iowa \
--output_csv=ia_county_seats.csv
The generated CSV is now available here: https://github.com/fadend/county_seat_coords/blob/main/county_seat_coords/generated/ia_usa_county_seats.csv. One complication that it doesn’t handle: Lee County has *two* county seats.
A little copying pasting from the R code from the other post produced a pretty okay map:
library(ggplot2)
library(ggrepel)
# Note: map_data is provided by ggplot2.
states <- map_data("state")
counties <- map_data("county")
ia <- states[states$region == "iowa", ]
ia_counties <- counties[counties$region == "iowa", ]
seats <- read.csv("~/projects/seatenv/ia_county_seats.csv", stringsAsFactors=FALSE)
ia_base <- ggplot(data=ia, mapping=aes(x=long, y=lat, group=group)) +
coord_quickmap() +
geom_polygon(color="black", fill="gray")
ia_base + theme_void() +
geom_polygon(data=ia_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)
Leave a Reply