Unfamiliar Maps

Many towns and cities share the same name. Some are less well known than others. Let’s take a look.

David Friggens
2016-08-14

At least 3 people have booked flights to Sydney, Nova Scotia (population 30,000) intending to holiday in New South Wales (two orders of magnitude larger). There are a number of cases like this of towns and cities with larger and more well known doppelgangers. I thought it would be interesting to have a map that labelled the familiar names in the unfamiliar locations.

This is fairly easy to do in R, given the data that comes with the maps package. But bear in mind that the data is neither 100% accurate nor complete. Also, it was a mostly manual selection of what to include, based on my interpretations of what is interesting and well known. Feel free to make your own version, based on your knowledge and familiarity of the globe.

We can add labels to the map using the leaflet package. The cities are grouped by the continental region of the (main) familiar city.

Notes

Code listing

The R code to generate the map:


library(maps)
library(leaflet)
library(dplyr)
library(purrr)
data("world.cities")

# Manually prepared file giving name and region, and when ordered by population,
# how many of the largest are "familiar" and how many of the smallest are "unfamiliar"
my_cities <- readr::read_csv("data/familiar_cities.csv")

familiar <- 
  my_cities %>%
  inner_join(world.cities) %>% 
  group_by(name) %>% 
  mutate(rank_desc = rank(-pop)) %>% 
  filter(rank_desc <= num_familiar) %>% 
  ungroup() %>% 
  select(-num_familiar, -num_unfamiliar, -rank_desc)

unfamiliar <- 
  my_cities %>%
  inner_join(world.cities) %>% 
  group_by(name) %>% 
  mutate(rank_asc = rank(pop)) %>% 
  filter(rank_asc <= num_unfamiliar) %>% 
  ungroup() %>% 
  select(-num_familiar, -num_unfamiliar, -rank_asc)
leaflet(width = "100%") %>% 
  addProviderTiles("Esri.WorldGrayCanvas") %>% 
  addCircleMarkers(
    data = familiar %>% filter(region == "Americas"),
    group = "Americas - Familiar",
    radius = 6,
    stroke = FALSE,
    fillOpacity = 0.5,
    color = "red",
    label = ~name,
    labelOptions = labelOptions(noHide = T)) %>% 
  addCircleMarkers(
    data = unfamiliar %>% filter(region == "Americas"),
    group = "Americas - Unfamiliar",
    radius = 6,
    stroke = FALSE,
    fillOpacity = 0.5,
    color = "navy",
    options = markerOptions(riseOnHover = TRUE),
    label = ~name,
    labelOptions = labelOptions(noHide = T)) %>% 
  addCircleMarkers(
    data = familiar %>% filter(region == "Asia-Pacific"),
    group = "Asia/Pacific - Familiar",
    radius = 6,
    stroke = FALSE,
    fillOpacity = 0.5,
    color = "red",
    label = ~name,
    labelOptions = labelOptions(noHide = T)) %>% 
  addCircleMarkers(
    data = unfamiliar %>% filter(region == "Asia-Pacific"),
    group = "Asia/Pacific - Unfamiliar",
    radius = 6,
    stroke = FALSE,
    fillOpacity = 0.5,
    color = "navy",
    options = markerOptions(riseOnHover = TRUE),
    label = ~name,
    labelOptions = labelOptions(noHide = T)) %>% 
  addCircleMarkers(
    data = familiar %>% filter(region == "Europe-Africa"),
    group = "Europe/Africa - Familiar",
    radius = 6,
    stroke = FALSE,
    fillOpacity = 0.5,
    color = "red",
    label = ~name,
    labelOptions = labelOptions(noHide = T)) %>% 
  addCircleMarkers(
    data = unfamiliar %>% filter(region == "Europe-Africa"),
    group = "Europe/Africa - Unfamiliar",
    radius = 6,
    stroke = FALSE,
    fillOpacity = 0.5,
    color = "navy",
    options = markerOptions(riseOnHover = TRUE),
    label = ~name,
    labelOptions = labelOptions(noHide = T)) %>% 
  addLayersControl(
    overlayGroups = c("Americas - Familiar", "Americas - Unfamiliar",
                      "Asia/Pacific - Familiar", "Asia/Pacific - Unfamiliar",
                      "Europe/Africa - Familiar", "Europe/Africa - Unfamiliar"),
    options = layersControlOptions(collapsed = FALSE)) %>% 
  hideGroup("Americas - Familiar") %>%
  hideGroup("Asia/Pacific - Familiar") %>% 
  hideGroup("Europe/Africa - Familiar")

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/dakvid/dakvid.github.io, unless otherwise noted. 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 ...".