library(tidyverse) # who doesn't want to be tidy
library(leaflet) # interactive mapping
library(mapview) # simple interactive mapping
library(sf) # geocoding objects
library(openxlsx) # importing excel files from a URL
TidyTuesday Week 27: Historical Markers
Today’s TidyTuesday is about historical markers with the data coming from the Historical Marker Database. I’m going to add to the map that I made last week with information about Historic Districts in Arlington, VA. I’m going to make an interactive leaflet map with the new information added to the old map.
Loading libraries.
I’m not going to loading the no markers data, because I know I’m not going to use it.
<- tidytuesdayR::tt_load(2023, week = 27) tuesdata
--- Compiling #TidyTuesday Information for 2023-07-04 ----
--- There are 2 files available ---
--- Starting Download ---
Downloading file 1 of 2: `historical_markers.csv`
Downloading file 2 of 2: `no_markers.csv`
--- Download complete ---
<- tuesdata$`historical_markers`
historical_markers #no_markers <- tuesdata$`no_markers`
The data isn’t very clean. The website might want to consider drop-down menus for some of the bigger groups. Here’s an illustration look at some of many ways people rendered “Kentucky Historical Society and Kentucky Department of Highways”.
%>% filter(state_or_prov == "Kentucky") %>%
historical_markers group_by(erected_by) %>% count(sort = TRUE) %>% filter(n > 50)
# A tibble: 10 × 2
# Groups: erected_by [10]
erected_by n
<chr> <int>
1 Kentucky Historical Society and Kentucky Department of Highways 634
2 Kentucky Historical Society, Kentucky Department of Highways 165
3 Kentucky Historical Society & Kentucky Department of Highways 159
4 Kentucky Historical Society, Kentucky Department of Highways. 141
5 the Kentucky Historical Society, Kentucky Department of Highways. 81
6 Kentucky Historical Society-Kentucky Department of Highways 79
7 Kentucky Department of Highways 75
8 Kentucky Historical Society • Kentucky Department of Highways 65
9 Kentucky Historical Society and Kentucky Department of Transportation 57
10 James Harrod Trust 53
Filtering for Virginia only. I could filter by county == "Arlington County"
also, but I actually want to get some of the adjacent markers, because I know there are some right on the county line and I’m not sure which jurisdiction they will fall in.
<- historical_markers %>% filter(state_or_prov == "Virginia") virginia_markers
I’m going to load in my data from the previous visualization. The blog post on how I created these objects is here.
<- st_read("points.shp")
historic_4269 <- st_read("polygons.shp") arlington_polygons_sf
Now I’m adding html tags and transforming the coordinate system. More about that here.
# turn the url to HTML anchor tag
<- historic_4269 %>%
historic_4269 mutate(tag = paste0("More Info: <a href=", Extrn_L,">", Extrn_L, "</a>"))
#transforming crs
<- sf::st_transform(historic_4269, crs = 4326)
historic_4326 <- sf::st_transform(arlington_polygons_sf, crs = 4326) arlington_polygons_sf_4326
Now I’m roughly sub-setting to Arlington based on latitude and longitude.
<-
va_markers_nova %>% filter(longitude_minus_w < -76.5 &
virginia_markers > -77.25) %>%
longitude_minus_w filter(latitude_minus_s > 38.8 &
< 39.4) latitude_minus_s
I know there is a lot of variation in the erected_by data (as seen for KY), so I’m going to check that out for this sub-set.
%>% group_by(erected_by) %>% count(sort = TRUE) va_markers_nova
# A tibble: 13 × 2
# Groups: erected_by [13]
erected_by n
<chr> <int>
1 Department of Historic Resources 34
2 Arlington County, Virginia 22
3 Arlington County Virginia 4
4 Arlington County 3
5 Conservation & Development Commission 3
6 Virginia Historic Landmarks Commission 3
7 City of Alexandria 1
8 Continental Chapter, Daughters of the American Revolution 1
9 The Washington Society of Alexandria, U.S. Dept. of the Interior 1
10 Virginia Conservation Commission 1
11 Virginia Department of Historic Resources 1
12 Washington-Lee Society, Children of the American Revolution; Thomas Ne… 1
13 William G. Pomeroy Foundation 1
Change all the Arlington stuff to Arlington County. The Conservation & Development Comission and the Virginia Conservation Commission are the same entity- the name changed over the years. I’m adding the years to those entries. I suspect they and the Virginia Landmarks Commission are all now replaced by the Virginia Department of Historic Resources, but I couldn’t find a source for that.
<- va_markers_nova %>%
va_markers_nova mutate(erected_by_clean = ifelse(
str_detect(erected_by, "Arlington County"),
"Arlington County",
erected_by%>%
)) mutate(
erected_by_clean = ifelse(
str_detect(erected_by_clean, "Historic Resources"),
"Virginia Dept. of Historic Resources",
erected_by_clean
)%>%
) mutate(
erected_by_clean = ifelse(
str_detect(erected_by_clean, "Conservation &"),
"Virginia Conservation & Development Commission (1926- 1938)",
erected_by_clean%>%
)) mutate(
erected_by_clean = ifelse(
str_detect(erected_by_clean, "Virginia Conservation Commission"),
"Virginia Conservation Commission (1938-1948)",
erected_by_clean ))
Checking our cleaned list.
%>% group_by(erected_by_clean) %>% count(sort = TRUE) va_markers_nova
# A tibble: 10 × 2
# Groups: erected_by_clean [10]
erected_by_clean n
<chr> <int>
1 Virginia Dept. of Historic Resources 35
2 Arlington County 29
3 Virginia Conservation & Development Commission (1926- 1938) 3
4 Virginia Historic Landmarks Commission 3
5 City of Alexandria 1
6 Continental Chapter, Daughters of the American Revolution 1
7 The Washington Society of Alexandria, U.S. Dept. of the Interior 1
8 Virginia Conservation Commission (1938-1948) 1
9 Washington-Lee Society, Children of the American Revolution; Thomas Ne… 1
10 William G. Pomeroy Foundation 1
Converting this to a sf object. For more information about that, see my last week’s TidyTuesday. Just take a quick look to make sure I’m happy. The mapview package is great for quick and dirty maps; I’ll use leaflet to make the fancy one.
<- st_as_sf(va_markers_nova, coords = c(9, 8), crs = 4326)
va_markers_nova_geo
mapview(va_markers_nova_geo) + mapview(historic_4326) + mapview(arlington_polygons_sf_4326)
Making the HTML anchor tag for my pop-up with a live link. This is covered in my leaflet revision to last week’s TidyTuesday.
# turn the url to HTML anchor tag
<- va_markers_nova_geo %>%
va_markers_nova_geo mutate(tag = paste0("More Info: <a href=", link,">", link, "</a>"))
A first view of the map.
<- colorFactor(palette = "viridis", domain = arlington_polygons_sf_4326$CIVIC)
pal
<- leaflet() %>%
leaflet_map addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(
data = arlington_polygons_sf_4326,
weight = 1,
label = ~ CIVIC,
color = ~ pal(CIVIC),
group = "Arlington Neighborhoods"
%>%
) addCircleMarkers(
data = historic_4326,
popup = ~ paste0("<b>", Prprt_N, "</b>", "<br>", tag),
# note the tilde notation!
opacity = 1,
radius = 7,
color = "black",
stroke = NA,
group = "Historic Neighborhoods"
%>%
) addCircleMarkers(
data = va_markers_nova_geo,
# note the tilde notation!
opacity = 1,
radius = 7,
color = "red",
stroke = NA,
group = "Historic Markers")
leaflet_map