airports <- read_csv("airports.csv")
## Rows: 19615 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (13): state, region, ado, city, county, facility_name, ownership, use, ...
## date (1): effective_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mnAirports <- airports %>%
filter(state == "MN") %>%
select(county, facility_name)
mnAirports2 <- mnAirports %>%
group_by(county) %>%
summarize(perCountyAirports = n())
mnAirports <- mnAirports %>%
left_join(mnAirports2) %>%
mutate(county = tolower(county)) %>%
mutate(county = str_to_title(county))
## Joining with `by = join_by(county)`
mnAirportsFinal <- mnAirports %>%
select(county, perCountyAirports) %>%
rename("NAME" = "county")
mnCounties <- read_sf("mnCounties", "county2010")
mnCounties <- mnCounties %>%
left_join(mnAirportsFinal)
## Joining with `by = join_by(NAME)`
pdf("choropleth.pdf",
width = 10,
height = 10)
ggplot() +
geom_sf(data = mnCounties, aes(fill = perCountyAirports), color='transparent') +
geom_sf(data = mnCounties, fill='transparent', color = 'white') +
scale_fill_viridis_b() +
theme(panel.background = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank()) +
labs(fill = "Airport Density", title = "Airports per Minnesota County", subtitle = "Urban counties have a higher airport density.", caption = "Source: US Airports by OpenIntro\nFirst Published: 10-25-2023\nLast Updated: 12-05-2023\nBen Tang")
dev.off()
## quartz_off_screen
## 2