The color of roads

Madison (WI) Dane County (WI) map

What colors are most represented in the road names of Dane County?

Harald Kliems https://haraldkliems.netlify.app/
2022-11-19

Sometimes you start a project and it ends up quite different from you had envisioned. I was going to do a quick and simple map for the #30DayMapChallenge theme “Blue.” Pull road data for Dane County, filter for names that contain “blue,” plot to a map with roads and road names. Sounds simple, right? Of course it is not.

Getting all the data in is straightforward with tigris and tmaptools.

Show code
library(tigris)
options(tigris_use_cache = TRUE)
library(tmap)
library(tmaptools)
library(sf)
library(tidyverse)
library(extrafont)
loadfonts(device = "all")

wi_roads <- roads("WI", "Dane")

# county shapefile to calculate bounding box for basemap download
dane <- tigris::counties("WI", cb = T) %>% 
  filter(NAME == "Dane")

#get basemap from OSM
dane_osm <- read_osm(bb(dane), zoom = 10, type = "stamen-toner", )

blue_dane <- wi_roads |> 
  mutate(blue = ifelse(str_detect(FULLNAME, "[Bb]lue"), "blue", "not blue")) |> 
  filter(blue == "blue") #keep only blue roads

blue_dane
Simple feature collection with 58 features and 5 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: -89.83851 ymin: 42.9267 xmax: -89.02944 ymax: 43.23245
Geodetic CRS:  NAD83
First 10 features:
        LINEARID            FULLNAME RTTYP MTFCC
1  1103738774528 Blue Bill Park Dr S     M S1400
2  1103738774530 Blue Bill Park Dr S     M S1400
3   110689766034 N Blue Bill Park Dr     M S1400
4  1106092748301    S Blue Mounds St     M S1400
5   110689763919    E Blue Mounds Rd     M S1400
6  1103676871652    E Blue Mounds Rd     M S1400
7   110689763921    W Blue Mounds Rd     M S1400
8   110689763922    W Blue Mounds Rd     M S1400
9   110689762152       Blue Ridge Ct     M S1400
10  110689765583   Blue Mountain Ave     M S1400
                         geometry blue
1  LINESTRING (-89.41119 43.14... blue
2  LINESTRING (-89.41047 43.15... blue
3  LINESTRING (-89.4134 43.158... blue
4  LINESTRING (-89.74511 42.99... blue
5  LINESTRING (-89.73772 42.95... blue
6  LINESTRING (-89.74274 42.96... blue
7  LINESTRING (-89.81902 42.96... blue
8  LINESTRING (-89.81824 42.97... blue
9  LINESTRING (-89.49303 43.07... blue
10 LINESTRING (-89.81777 43.01... blue

But a map shows that more work is needed:

Show code
tm_shape(dane_osm) +
  tm_rgb() +
  tm_shape(blue_dane) +
  tm_lines("blue", lwd = 2) +
  tm_text("FULLNAME", col = "blue")

Not good: The labels are too crowded, and you can see that a single way with the same name often is split into multiple segments, e.g. Blue Mounds Trail on the western edge of the map. I spent hours trying to fix these things through one of the various geometric or other tools from the sf package. But in the end, nothing worked. (If you have suggestions on how to combine adjoining ways, I’m all ears!)

Instead, I pivoted to making a map of all the road name colors in Dane County. The colors are extracted with simple regular expressions. This works well for all colors except “red” – RiveREDege Ct, LaREDo Ct, or EldRED St are just some of the false positives. For one county these can be cleaned manually, but for a larger dataset this would be a problem.

Show code
# deal with false-positive reds
not_red <- c("Riveredge Rd", 
             "Laredo Ct",
             "Eldred St", 
             "Fredericksburg Ct", 
             "Frederick Ct", 
             "Arboredge Way", 
             "Frederick Cir",
             "Redan Dr",
             "Meredith Way",
             "Claredon Dr",
             "Frederick St",
             "Fredericksburg Ln",
             "Meredithe Ave",
             "Arboredge Way",
             "Fredenberg Rd",
             "Mildred Ct",
             "Hubred Ln",
             "Covered Bridge Trl",
             "Saddle Bred Ln",
             "Saddlebred Ln")

blue_dane <- wi_roads |> 
  mutate(blue = case_when(str_detect(FULLNAME, "[Bb]lue") ~ "blue",
                          str_detect(FULLNAME, "[Bb]lack") ~ "black",
                          str_detect(FULLNAME, "[Rr]ed") ~ "red",
                          str_detect(FULLNAME, "[Yy]ellow") ~ "yellow",
                          str_detect(FULLNAME, "[Bb]rown") ~ "brown",
                          str_detect(FULLNAME, "[Gg]r[ae]y") ~ "grey",
                          str_detect(FULLNAME, "[Gg]reen") ~ "green",
                          T ~ NA_character_)) |> 
  filter(!is.na(blue) & !blue %in% not_red)

Which color is most common?

Show code
blue_dane |> 
  st_drop_geometry() |>
  group_by(blue) |> 
  tally(sort = T) |> 
  knitr::kable()
blue n
green 88
red 69
blue 58
black 40
grey 13
brown 8
yellow 8

Green! And here are the two maps, one dynamic and one static:

Show code
tmap_mode("view")
tm_shape(blue_dane) +
  tm_lines("blue",lwd = 3, alpha = .8,  id = "FULLNAME") +
  tm_layout(title = "The Color of Dane County Road Names")
Show code
tmap_mode("plot")
tm_shape(dane_osm) +
  tm_rgb(alpha = .7) +
  tm_shape(blue_dane) +
  tm_lines("blue",lwd = 3, alpha = .8) +
  tm_layout(title = "The Color of Dane County Road Names", fontfamily = "Roboto Condensed", title.bg.color = "lightgrey", title.bg.alpha = .8)

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY-SA 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Kliems (2022, Nov. 19). Harald Kliems: The color of roads. Retrieved from https://haraldkliems.netlify.app/posts/2022-11-19-the-color-of-roads/

BibTeX citation

@misc{kliems2022the,
  author = {Kliems, Harald},
  title = {Harald Kliems: The color of roads},
  url = {https://haraldkliems.netlify.app/posts/2022-11-19-the-color-of-roads/},
  year = {2022}
}