Rows: 31254 Columns: 17
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (9): city, city_ascii, state_id, state_name, county_fips, county_name, s...
dbl (6): lat, lng, population, density, ranking, id
lgl (2): military, incorporated
ℹ 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.
# Convert us_cities df to an sf object using lng and latcities_sf <-st_as_sf(us_cities, coords =c("lng", "lat"), crs =4326)# Get the spatial boundary of Larimer County, COboundary <-aoi_get(state ="CO", county ="Larimer")# Filter cities located in Larimer Countylarimer_cities <- cities_sf %>%filter(county_name =="Larimer")# Identify the top 3 most populous cities in Larimer Countytop_3_cities <- larimer_cities %>%slice_max(population, n =3)# Create spatial plot (map)larimer_pop_map <-ggplot() +geom_sf(data = boundary, fill =NA, color ="black", size =1) +geom_sf(data = larimer_cities, fill ="lightgray", color ="darkgray") +geom_sf(data = top_3_cities, color ="red", size =3) +theme_void() +labs(title ="Cities in Lairmer County",subtitle ="Red points: 3 Most Populous Cities") +theme(plot.title =element_text(hjust =0.5), plot.subtitle=element_text(hjust =0.5)) +geom_label_repel(data = top_3_cities, aes(label = city, geometry = geometry), stat ="sf_coordinates", size =3)# Save the plot to images dirggsave(filename ="../images/larimer_pop_map.png", plot = larimer_pop_map, width =8, height =6, dpi =600)
Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
give correct results for longitude/latitude data