── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(units)
Warning: package 'units' was built under R version 4.4.3
udunits database from C:/Users/Zacha/AppData/Local/R/win-library/4.4/units/share/udunits/udunits2.xml
library(flextable)
Warning: package 'flextable' was built under R version 4.4.3
Attaching package: 'flextable'
The following object is masked from 'package:purrr':
compose
library(ggplot2)library(sf)
Warning: package 'sf' was built under R version 4.4.3
Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE
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.
cities_sf <-st_as_sf(cities, coords =c("lng", "lat"), crs =4269) cities_sf <-st_transform (cities_sf, 5070) cities_in_ms_counties <-st_join(cities_sf, ms_counties, join = st_intersects)# Calculate the total urban population in each countypop_by_county <- cities_in_ms_counties %>%group_by(county_name) %>%summarise(total_population =sum(population, na.rm =TRUE))ms_counties_pop <- ms_counties %>%st_join(pop_by_county, by ="GEOID")# plotggplot() +geom_sf(data = conus_counties, color ="darkgrey", fill ="white") +geom_sf(data = ms_counties_pop, aes(fill = total_population), color =NA) +geom_sf(data = MS_rivers, color ="lightblue", size =0.4) +scale_fill_viridis_c (na.value ="grey80") +theme_void() +labs(title ="Urban Population in Counties Intersecting the Mississippi River System",fill ="Urban Population")