This needs some touchup to nudge a few state names, callouts on the smaller states lose the axis names and long/lat grid.
library(ggplot2)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
library(tidycensus)
library(tigris)
#> To enable caching of data, set `options(tigris_use_cache = TRUE)`
#> in your R script or .Rprofile.
options(tigris_use_cache = TRUE)
basemap <- get_acs(
geography = "state",
variables = "B01002_001",
year = 2019,
survey = "acs1",
geometry = TRUE,
resolution = "20m",
cache_table = TRUE
) |> shift_geometry()
#> Getting data from the 2019 1-year ACS
#> The 1-year ACS provides data for geographies with populations of 65,000 and greater.
basemap <- basemap[c(1, 2, 6)]
converter <- data.frame(
NAME = c(
"Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware",
"District of Columbia", "Florida", "Georgia", "Hawaii",
"Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan",
"Minnesota", "Mississippi", "Missouri", "Montana",
"Nebraska", "Nevada", "New Hampshire", "New Jersey",
"New Mexico", "New York", "North Carolina", "North Dakota",
"Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Puerto Rico",
"Rhode Island", "South Carolina", "South Dakota", "Tennessee",
"Texas", "Utah", "Vermont", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming"
),
ABBR = c(
"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC",
"FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
"ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV",
"NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA",
"PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA",
"WV", "WI", "WY"
)
)
basemap <- dplyr::left_join(basemap, converter)
#> Joining with `by = join_by(NAME)`
abbr_loc <- st_coordinates(st_centroid(basemap$geometry))
basemap <- cbind(basemap, abbr_loc)
ggplot(basemap) +
geom_sf(data = basemap) +
geom_text(aes(X, Y, label = ABBR), size = 3) +
theme_minimal()