#30DayMapChallenge: A “bad” map of the US

map

Places that start with “bad” (but not “badger”!)

Harald Kliems https://haraldkliems.netlify.app/
2023-11-04

The theme for today’s #30DayMapChallenge: Bad maps. Inspired by this map of German town’s starting with “Bad” (designating a spa town), I thought I’d do something similar for the US.

We get places names from the USGS Gazetteer files. Be warned that these are large files that will take a while to download and read.

Show code
library(tidyverse)
library(sf)
library(tmap)
url <- "https://prd-tnm.s3.amazonaws.com/StagedProducts/GeographicNames/FullModel/Gazetteer_National_GDB.zip"
zip_file <- tempfile(fileext = ".zip")
options(timeout=180) #file is large and times out with default timeout
download.file(url, zip_file, mode = "wb")
temp_dir <- tempdir()
places_dir <- unzip(zipfile = zip_file, exdir = temp_dir)

gazetteer_places <- st_read(paste0(temp_dir, "\\Gazetteer_National_GDB.gdb"), layer = "Gaz_Names") #layer with names
Reading layer `Gaz_Names' from data source 
  `C:\Users\user1\AppData\Local\Temp\RtmpkZQ702\Gazetteer_National_GDB.gdb' 
  using driver `OpenFileGDB'
Show code
gazetteer_geo <- st_read(paste0(temp_dir, "\\Gazetteer_National_GDB.gdb"), layer = "Gaz_Features")
Reading layer `Gaz_Features' from data source 
  `C:\Users\user1\AppData\Local\Temp\RtmpkZQ702\Gazetteer_National_GDB.gdb' 
  using driver `OpenFileGDB'
Simple feature collection with 980622 features and 19 fields
Geometry type: MULTIPOINT
Dimension:     XYZ
Bounding box:  xmin: -179.4681 ymin: -85.37423 xmax: 179.9833 ymax: 71.41745
z_range:       zmin: 0 zmax: 0
Geodetic CRS:  NAD83
Show code
all_places <- gazetteer_geo |> right_join(gazetteer_places, by = "feature_id")

Now we start filtering for places starting with “Bad”:

Show code
bad_places <- all_places |> 
  filter(str_detect(feature_name, "^[Bb]ad"))

This gives us 640 places, but just looking at the names of the first few shows that they’re not all “bad” places:

Show code
head(bad_places$feature_name)
[1] "Bad River"                    "Badger Creek"                
[3] "Badger Mountain Division"     "Bad River Indian Reservation"
[5] "Bad River Reservation"        "Badwater Creek"              

Two out of the 6 are not “bad” but “Badger.” After browsing through the full list of included names, I came with this heuristic to eliminate most “non-bad” names, such as “Baden,” “Badoff,” or “Badito.”

Show code
bad_places <- bad_places |> 
  filter(!str_detect(feature_name, "^[Bb]ad[degiou]"))
bad_places |> 
  st_drop_geometry() |> 
  select(feature_name, feature_class) |> 
  DT::datatable()

What type of places are most commonly bad?

Show code
bad_places |> 
  st_drop_geometry() |> 
  group_by(feature_class) |> 
  tally(sort = T) |> 
  DT::datatable()

Streams!

Let’s map all the 209 bad places:

Show code
tmap_mode("view")
tm_shape(bad_places) +
  tm_dots("feature_class", id = "feature_name",
          popup.vars = c("Type of feature" = "feature_class")) +
  tm_layout(title = "Bad Places in the United States")

You can click on the points to display the name. We could add the names right on the map, but as bad places cluster together (and in the case of rivers and streams, the same feature shows up multiple times), this makes for a messy map:

Show code
tm_shape(bad_places) +
  tm_dots("feature_class", id = "feature_name",
          popup.vars = c("Type of feature" = "feature_class")) +
  tm_text("feature_name")

That’s all for today.

Citation

For attribution, please cite this work as

Kliems (2023, Nov. 4). Harald Kliems: #30DayMapChallenge: A "bad" map of the US. Retrieved from https://haraldkliems.netlify.app/posts/2023-11-04-30daymapchallenge-a-bad-map-of-the-us/

BibTeX citation

@misc{kliems2023#30daymapchallenge:,
  author = {Kliems, Harald},
  title = {Harald Kliems: #30DayMapChallenge: A "bad" map of the US},
  url = {https://haraldkliems.netlify.app/posts/2023-11-04-30daymapchallenge-a-bad-map-of-the-us/},
  year = {2023}
}