Import locations and tidy data
library(tidyverse)
letter_locations <- read_csv("data/all_locations.csv")
colnames(letter_locations) <- tolower(make.names(colnames(letter_locations)))
## Fix bad encodings
letter_locations$country <-
gsub("\xa7", "ß", letter_locations$country) %>% # \xa7 is used instead of ß
gsub("\x8a", "ä", .) # \x8a is used instead of ä
letter_locations$city <-
gsub("\xa7", "ß", letter_locations$city) %>% # \xa7 is used instead of ß
gsub("\x8a", "ä", .) %>% # \x8a is used instead of ä
gsub("\x9a", "ö", .) %>%
gsub("\x9f", "ü", .) %>%
gsub("'", "", .) %>%
gsub("\x8e", "é", .)
# letter_locations$brackets <-
# gsub("\xa7", "ß", letter_locations$brackets) %>% # \xa7 is used instead of ß
# gsub("\x8a", "ä", .) %>% # \x8a is used instead of ä
# gsub("\x9a", "ö", .) %>%
# gsub("\x9f", "ü", .)
## Test encoding with: parse(text = paste0("'", letter_locations$country , "'"))
Basic map
library(leaflet)
letter_locations %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(popup = ~city)
Labeller
location_label <- function(country = NA, city = NA, brackets = NA){
paste0(
"<p>Country:",
country,
"</p>",
"<p>City:",
city,
"</p>"
)
}
Labelled locations, with clustering
letter_locations %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(popup = ~location_label(country, city, brackets), clusterOptions = markerClusterOptions())
## Converting the xlsx to csv interactively introduced hundreds of empty columns, this code fixes
# letters_for_geo_viz <- read_csv("data/letters_for_geoviz.csv")
# colnames(letters_for_geo_viz) <- gsub(" ", ".", colnames(letters_for_geo_viz)) %>%
# tolower()
# write_csv(x = letters_for_geo_viz[, colnames(letters_for_geo_viz)[!grepl("x", colnames(letters_for_geo_viz))]],
# path = "data/letters_for_geoviz.csv")
letters_for_geo_viz <- read_csv("data/all_letters.csv")
library(lubridate)
letters_for_geo_viz$date <- dmy(letters_for_geo_viz$date)
## Fix bad encodings
letters_for_geo_viz$location.sender <-
gsub("\xa7", "ß", letters_for_geo_viz$location.sender) %>% # \xa7 is used instead of ß
gsub("\x8a", "ä", .) %>% # \x8a is used instead of ä
gsub("\x9a", "ö", .) %>%
gsub("\x9f", "ü", .) %>%
gsub("'", "", .) %>%
gsub("\x8e", "é", .)
letters_for_geo_viz$location.receiver <-
gsub("\xa7", "ß", letters_for_geo_viz$location.receiver) %>% # \xa7 is used instead of ß
gsub("\x8a", "ä", .) %>% # \x8a is used instead of ä
gsub("\x9a", "ö", .) %>%
gsub("\x9f", "ü", .) %>%
gsub("'", "", .) %>%
gsub("\x8e", "é", .)
Locations given as “location sender” that do not appear in the unique locations:
setdiff(letters_for_geo_viz$location.sender, letter_locations$location.string)
## [1] NA
## [2] "USA,"
## [3] "USA, Santa Fé (NM)"
## [4] "CHE, Schloß \rWolfsberg, Gemeinde Ermatingen Kanton \rThurgau"
## [5] "CHE, Hohenheim"
## [6] "GBR, someplace"
## [7] "GER, Pünderich"
## [8] "GER, Delbrück"
## [9] "GER, Göttingen"
## [10] "Gr. Stove."
## [11] "USA, ?"
## [12] "GER, Münster"
## [13] "?"
## [14] "USA, Loebenwoth"
## [15] "USA, Ponkipsien"
## [16] "GER, Osnabrück"
## [17] "FRA Paris"
## [18] "USA, Camp near Morgangia"
## [19] "USA, National (IA)"
## [20] "USA, Fishers Island (NY)"
## [21] "GER, Köpenick (GER, Berlin?"
## [22] "GER, Bad Lobenstein (Thüringen)"
## [23] "USA, Camp Hales Springs, 5 miles west of Crockett, Houston County (TX)"
## [24] "USA, Camp Daviss Musell Creek Panola County (TX)"
## [25] "USA, Camp Tippa mouth (MS)"
## [26] "USA, Camp Synders Bluff, Yazoo River (MS)"
## [27] "USA, Johnsons Island (OH)"
## [28] "USA, Bradys Bend (PA)"
## [29] "GER, Lüdingheim"
## [30] "USA, Camp Steele"
## [31] "USA"
## [32] "USA, AmeriCAN Goldmine, Union County (NC)"
## [33] "USA, Camp Stude (MS)"
## [34] "USA, near CANteen Township (IL)"
## [35] "USA, Goodings Farm (VA)"
## [36] "GER, Müsen"
Locations given as “location receiver” that do not appear in the unique locations:
setdiff(letters_for_geo_viz$location.receiver, letter_locations$location.string)
## [1] NA
## [2] "GER,"
## [3] "Ger Cologne"
## [4] "Ger"
## [5] "GER, Bremervörde"
## [6] "GER, Pünderich"
## [7] "GER, Delbrück"
## [8] "?"
## [9] "mutmaßlicher Ankunft in der Näe von Bärendorf (Schlesien, in 010 wird über Breslau geredet)"
## [10] "GER, Lüdenscheid"
## [11] "GER, Lüneburg"
## [12] "GER, Rheda Wiedenbrück"
## [13] "USA,"
## [14] "POL, Dorzyskowo (vermutlich Gorzyskowo, nähe Bromberg, heute Polen)"
## [15] "GER, Warnemünde"
## [16] "USA"
## [17] "GER, München"
## [18] "GER, GER,tz"
## [19] "GER, Wolfenbüttel"
## [20] "in der Serie werden häufig Ortsnamen (allerdings nicht die Orte des Empfängers sondern die mit anderen Personen zusammenhängen) die beiderseitig der heutigen Grenze zwischen Rheinland-Pfalz und dem GER,tschsprachigen Belgien liegen (z.B. Manderfeld, Prüm)"
## [21] "GER, Münster"
## [22] "GER, Unterlübbe"
## [23] "GER, Lüdingheim"
## [24] "GER, Ibbenbüren"
## [25] "GER, GER, Berlin?"
## [26] "GER, Müsen"
Make routes
locations_df <- letter_locations %>%
mutate(loc.id = 1:nrow(letter_locations))
library(plyr)
letters_for_geo_viz <- letters_for_geo_viz %>%
mutate(send.loc = as.numeric(mapvalues(location.sender, from = locations_df$location.string, to = locations_df$loc.id, warn_missing = F))) %>%
mutate(receive.loc = as.numeric(mapvalues(location.receiver, from = locations_df$location.string, to = locations_df$loc.id, warn_missing = F)))
As a graph, because why not?
edges <- data.frame(
from = letters_for_geo_viz$send.loc,
to = letters_for_geo_viz$receive.loc
) %>%
na.omit() %>%
unique()
nodes <- data.frame(
id = locations_df$loc.id,
title = paste0(locations_df$country, ", ", locations_df$city),
label = locations_df$country
) %>%
na.omit()
library(igraph)
library(visNetwork)
igraph_letters <- graph.data.frame(edges, vertices = nodes)
visIgraph(igraph_letters,idToLabel = F)