Take home Exercise 5

Visualising and Analysing Geographic and Movement Data

Author

Affiliation

Bomin Kim

 

Published

May 28, 2022

DOI

Overview

In HW5 we will mainly focus on answering the bullet point 1 and 2 of challenge 2 in VAST 2022, ie.

  1. Social area layouts in city of Engagement, Ohio USA
  2. Locations with traffic bottleneck of the city of Engagement, Ohio USA

Part 1. City layout

Loading packages

packages = c('tidyverse','knitr','tmap','readr','sf','clock')
for(p in packages){
  if(!require(p, character.only = T)){
    install.packages(p)
  }
  library(p, character.only = T)
}

Data reading with read_sf function.

schools <- read_sf("data/Attributes/Schools.csv", 
                   options = "GEOM_POSSIBLE_NAMES=location")  
pubs <- read_sf("data/Attributes/Pubs.csv", 
                   options = "GEOM_POSSIBLE_NAMES=location")
apartments <- read_sf("data/Attributes/Apartments.csv", 
                   options = "GEOM_POSSIBLE_NAMES=location")
buildings <- read_sf("data/Attributes/Buildings.csv", 
                   options = "GEOM_POSSIBLE_NAMES=location")
employers <- read_sf("data/Attributes/Employers.csv", 
                   options = "GEOM_POSSIBLE_NAMES=location")
restaurants <- read_sf("data/Attributes/Restaurants.csv", 
                   options = "GEOM_POSSIBLE_NAMES=location")

Building layout by basic funtions

tmap_mode("view")
tm_shape(buildings)+
tm_polygons(col = "buildingType",
           palette="Accent",
           border.col = "black",
           border.alpha = .5,
           border.lwd = 0.5)
buildingType
Commercial
Residental
School
Leaflet | Tiles © Esri — Esri, DeLorme, NAVTEQ
tmap_mode("view")

Apartments layout by Rental Cost.

apartments$rentalCost <- as.numeric(apartments$rentalCost)
apartments$numberOfRooms <- as.numeric(apartments$numberOfRooms)
apartments$maxOccupancy <- as.numeric(apartments$maxOccupancy)

tmap_mode("view")
tm_shape(buildings)+
tm_polygons(col = "buildingType",
           palette="Accent",
           border.col = "black",
           border.alpha = 0.4,
           border.lwd = 0.3)+
tm_shape(apartments)+
tm_bubbles(col = "rentalCost",
           alpha = 0.4,
           n = 4,
           style = "jenks",
           palette="OrRd",
           size = "numberOfRooms",
           scale = 0.4,
           border.col = "black",
           border.lwd = 0.3)
buildingType
Commercial
Residental
School
rentalCost
348 to 636
636 to 905
905 to 1,190
1,190 to 1,601
Leaflet | Tiles © Esri — Esri, DeLorme, NAVTEQ
tmap_mode("view")

Employers layout by # of ppl employed (headcouts).

Jobs<-readRDS("data/Jobs.rds")

employers$employerId <- as.numeric(employers$employerId)
employers$buildingId <- as.numeric(employers$buildingId)

weeklypay_employer <- Jobs %>%
  group_by(employerId) %>%
  summarise(
    n=n(),
    mean=mean(totalweeklypay))
colnames(weeklypay_employer)[2] <- "headcount"
colnames(weeklypay_employer)[3] <- "averagepay"

employers<-weeklypay_employer %>%
    select("employerId","headcount","averagepay") %>%
    distinct() %>%
    left_join(employers, by = 'employerId')

employers1<-st_as_sf(employers)

tmap_mode("view")
tm_shape(buildings)+
tm_polygons(col = "buildingType",
           palette="Accent",
           border.col = "black",
           border.alpha = 0.4,
           border.lwd = 0.3)+
tm_shape(employers1)+
tm_bubbles(col = "headcount",
           alpha = 0.4,
           n = 4,
           style = "cont",
           palette="OrRd",
           scale = 0.4,
           border.col = "black",
           border.lwd = 0.3)
buildingType
Commercial
Residental
School
headcount
2345678

Leaflet | Tiles © Esri — Esri, DeLorme, NAVTEQ
tmap_mode("view")

Employers layout by weekly average salary.

tmap_mode("view")
tm_shape(buildings)+
tm_polygons(col = "buildingType",
           palette="Accent",
           border.col = "black",
           border.alpha = 0.4,
           border.lwd = 0.3)+
tm_shape(employers1)+
tm_bubbles(col = "averagepay",
           alpha = 0.4,
           n = 4,
           style = "cont",
           palette="viridis",
           scale = 0.4,
           border.col = "black",
           border.lwd = 0.3)
buildingType
Commercial
Residental
School
averagepay
6008001,0001,2001,400

Leaflet | Tiles © Esri — Esri, DeLorme, NAVTEQ
tmap_mode("view")

Pubs layout by hourly cost.

pubs$hourlyCost <- as.numeric(pubs$hourlyCost)

tmap_mode("view")
tm_shape(buildings)+
tm_polygons(col = "buildingType",
           palette="Accent",
           border.col = "black",
           border.alpha = 0.4,
           border.lwd = 0.3)+
tm_shape(pubs)+
tm_bubbles(col = "hourlyCost",
           alpha = 0.4,
           n = 4,
           style = "jenks",
           palette="Reds",
           scale = 0.4,
           border.col = "black",
           border.lwd = 0.3)
buildingType
Commercial
Residental
School
hourlyCost
6.42 to 8.28
8.28 to 10.52
10.52 to 12.58
12.58 to 14.84
Leaflet | Tiles © Esri — Esri, DeLorme, NAVTEQ
tmap_mode("view")

Schools layout by monthly cost.

schools$monthlyCost <- as.numeric(schools$monthlyCost)

tmap_mode("view")
tm_shape(buildings)+
tm_polygons(col = "buildingType",
           palette="Accent",
           border.col = "black",
           border.alpha = 0.4,
           border.lwd = 0.3)+
tm_shape(schools)+
tm_bubbles(col = "monthlyCost",
           alpha = 0.4,
           n = 4,
           style = "jenks",
           palette="Blues",
           scale = 0.4,
           border.col = "black",
           border.lwd = 0.3)
buildingType
Commercial
Residental
School
monthlyCost
12.81 to 12.81
12.81 to 32.40
32.40 to 71.56
71.56 to 91.14
Leaflet | Tiles © Esri — Esri, DeLorme, NAVTEQ
tmap_mode("view")

Part 2. Traffic bottleneck

From travelJournal we can find out the frequency of building ID’s occurrence. We have cleaned the data to the minimum size that includes the location geometric information. However, the hex method failed to capture the occurrence of the geometric ID, most of the occurrence fell in NA category. Thus below table is a gimps of a clean data table that includes occurrence and location ID.

travellocation<-readRDS("data/travellocation2.rds")

knitr::kable(head(travellocation), format = 'html')
travelStartLocationId location
1 POLYGON ((350.0639 4595.666…
1 POLYGON ((350.0639 4595.666…
1 POLYGON ((350.0639 4595.666…
1 POLYGON ((350.0639 4595.666…
1 POLYGON ((350.0639 4595.666…
1 POLYGON ((350.0639 4595.666…