Experiment
library(ggregions)
# Step 1 Prepare reference data set
nc_ref <- sf::st_read(system.file("shape/nc.shp", package="sf")) |>
select(county_name = NAME,
county_fips = FIPS,
geometry)
## Reading layer `nc' from data source
## `/Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library/sf/shape/nc.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 100 features and 14 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
## Geodetic CRS: NAD27
nc_cities_ref <- maps::us.cities |>
filter(country.etc == "NC") |>
mutate(name = str_remove(name, " NC")) |>
sf::st_as_sf(coords = c("long", "lat"), agr = "constant") |>
select(name, geometry)
sf::st_crs(nc_cities_ref) <- "NAD27"
# Step 1 Declare reference data
set_regions(regions = nc_ref,
locales = nc_cities_ref)
nc_ref |>
bind_rows(nc_cities_ref) |>
tail()
## Simple feature collection with 6 features and 3 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -80.26 ymin: 34.21 xmax: -77.4 ymax: 36.1
## Geodetic CRS: NAD27
## county_name county_fips name geometry
## 115 <NA> <NA> Jacksonville POINT (-77.4 34.76)
## 116 <NA> <NA> Raleigh POINT (-78.66 35.82)
## 117 <NA> <NA> Rocky Mount POINT (-77.81 35.96)
## 118 <NA> <NA> Wilmington POINT (-77.91 34.21)
## 119 <NA> <NA> Wilson POINT (-77.92 35.73)
## 120 <NA> <NA> Winston-Salem POINT (-80.26 36.1)
ggplot() +
stamp_region() +
ggregions:::stamp_locale_label()
## Warning in layer_sf(geom = GeomSfDarker, data = ref_data, mapping = mapping, :
## Ignoring unknown parameters: `aes_name`
## Warning in layer_sf(geom = GeomLabel, data = data, mapping = mapping, stat =
## stat, : Ignoring unknown parameters: `aes_name`
## Coordinate system already present.
## ℹ Adding new coordinate system, which will replace the existing one.
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data
