In the first section, you need to select one Census Tract that you think is the most walkable and another one that you think is least walkable within Fulton and DeKalb Counties, GA. As long as the two Census Tracts are within the two counties, you can pick any two you want. If the area you want to use as walkable/unwalkable area is not well-covered by one Census Tract, you can select multiple tracts (e.g., selecting three adjacent tracts as one walkable area). The definition of ‘walkable’ can be your own - you can choose solely based on your experience (e.g., had best/worst walking experience), refer to Walk Score, or any other mix of criteria you want. After you make the selection, provide a short write-up with a map explaining why you chose those Census Tracts.
The second section is the main part of this assignment in which you prepare OSM data, download GSV images, apply computer vision (i.e., semantic segmentation).
In the third section, you will summarise and analyze the output and provide your findings. After you apply computer vision to the images, you will have the number of pixels in each image that represent 150 categories in your data. You will focus on the following categories in your analysis: building, sky, tree, road, and sidewalk. Specifically, you will (1) create maps to visualize the spatial distribution of different elements, (2) compare the mean of each category between the two Census Tract and (3) draw box plots to compare the distributions.
library(tidyverse)
library(tidycensus)
library(osmdata)
library(sfnetworks)
library(units)
library(sf)
library(tidygraph)
library(tmap)
library(here)
library(nominatimlite)
library(leaflet)
library(dplyr)
ttm()
Select walkable Census Tract(s) and unwalkable Census Tract(s) within Fulton and DeKalb counties.
In the quest to search for Census Tracts, you can use an approach similar to what we did in Step 1 of ‘Module4_getting_GSV_images.Rmd’. This time, instead of cities, we are focusing on Census Tracts; and the search boundary is the two counties, instead of metro Atlanta.
Provide a brief description and visualization of your Census Tracts. Why do you think the Census Tracts are walkable and unwalkable? What were the contributing factors?
# get tract
tract<-get_acs(geography = "tract",
state = "GA",
county = c("Fulton", "Dekalb"),
variables = c(hhincome = 'B19019_001',
race.tot = "B02001_001",
race.white = "B02001_002",
race.black = 'B02001_003'
),
year = 2019,
survey = "acs5", # American Community Survey 5-year estimate
geometry = TRUE, # returns sf objects
output = "wide")
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|====== | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 12%
|
|========= | 13%
|
|========== | 14%
|
|============ | 16%
|
|============ | 18%
|
|============= | 19%
|
|============== | 20%
|
|=============== | 21%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|======================= | 32%
|
|======================== | 34%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================= | 42%
|
|============================== | 43%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|====================================== | 54%
|
|======================================= | 56%
|
|======================================== | 57%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|================================================ | 68%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|====================================================== | 77%
|
|======================================================= | 79%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================== | 82%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 86%
|
|============================================================== | 88%
|
|=============================================================== | 90%
|
|================================================================ | 92%
|
|================================================================= | 93%
|
|=================================================================== | 95%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
# wolkscore data
walkscore<-read.csv("D:/Storage/Master/23fall/CP6088 Intro to Urban Analytics/6088assn3/walkscore_4counties.csv")%>%
select(GEOID="TractID",walkscore,cbd_dist,in.atl)
walkscore$GEOID<-as.character(walkscore$GEOID)
tract_wolkscore<-left_join(tract,walkscore,by="GEOID")%>%mutate(rowid=row_number())
which.max(tract_wolkscore$walkscore)
## [1] 220
which.min(tract_wolkscore$walkscore)
## [1] 203
# view tract
tract_wolkscore$rowid<-as.character(tract_wolkscore$rowid)
class(tract_wolkscore$rowid)
## [1] "character"
tm_shape(tract_wolkscore)+tm_borders()+
tm_fill(col="walkscore",popup.vars = c("rowid","walkscore"))
I evaluate the walkability of census tract according to the walkscore data from https://www.walkscore.com. I choose relatively small census tract because I don’t want a high volume of data. For walkable tract, I choose 13121003000(GEOID) from the range of walk score 0-20. For unwalkable one, I choose 13089021217 from the range of 80-100.
Fill out the template to complete the script.
# TASK ////////////////////////////////////////////////////////////////////////
# 1. Set up your api key here
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Download Census Tract polygon for Fulton and DeKalb
tract <- get_acs("tract",
variables = c('tot_pop' = 'B01001_001'),
year = 2020,
state = "GA",
county = c("Fulton", "DeKalb"),
geometry = TRUE)
## Getting data from the 2016-2020 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
##
|
| | 0%
|
|= | 2%
|
|== | 3%
|
|=== | 5%
|
|==== | 6%
|
|===== | 7%
|
|====== | 8%
|
|======= | 10%
|
|======== | 11%
|
|========= | 13%
|
|========== | 14%
|
|=========== | 16%
|
|============ | 17%
|
|============= | 18%
|
|============== | 20%
|
|=============== | 21%
|
|================ | 22%
|
|================= | 24%
|
|================== | 25%
|
|=================== | 27%
|
|==================== | 28%
|
|===================== | 30%
|
|===================== | 31%
|
|======================= | 32%
|
|======================= | 34%
|
|========================= | 35%
|
|========================= | 36%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================= | 46%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 56%
|
|======================================== | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|===================================================== | 75%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================== | 88%
|
|=============================================================== | 89%
|
|================================================================ | 91%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
# =========== NO MODIFY ZONE ENDS HERE ========================================
# TASK ////////////////////////////////////////////////////////////////////////
# The purpose of this TASK is to create one bounding box for walkable Census Tract and another bounding box for unwalkable Census Tract.
# As long as you generate what's needed for the subsequent codes, you are good. The numbered list of tasks below is to provide some hints.
# 1. Write the GEOID of walkable & unwalkable Census Tracts. e.g., tr1_ID <- c("13121001205", "13121001206")
# 2. Extract the selected Census Tracts using tr1_ID & tr2_ID
# 3. Create their bounding boxes using st_bbox(), and
# 4. Assign them to tract_1_bb and tract_1_bb, respectively.
# 5. Change the coordinate system to GCS, if necessary.
# For the walkable Census Tract(s)
# 1.
tr1_ID <- "13121003000"
# 2~4
tract_1_bb <- tract %>% filter(GEOID==tr1_ID)%>%
st_bbox()
head(tract%>% filter(GEOID==tr1_ID))
## Simple feature collection with 1 feature and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -84.36725 ymin: 33.75237 xmax: -84.34915 ymax: 33.76546
## Geodetic CRS: NAD83
## GEOID NAME variable estimate moe
## 1 13121003000 Census Tract 30, Fulton County, Georgia tot_pop 3679 481
## geometry
## 1 MULTIPOLYGON (((-84.36579 3...
#------check
tract_1_bb_sfc<-st_as_sfc(tract_1_bb)
tm_shape(tract_wolkscore)+tm_borders()+
tm_fill(col="walkscore",popup.vars = "rowid")+
tm_shape(tract_1_bb_sfc)+tm_borders()
#-------no problem
# For the unwalkable Census Tract(s)
# 1.
tr2_ID <- "13089021217"
# 2~4
tract_2_bb <- tract %>% filter(GEOID==tr2_ID)%>%
st_bbox()
head(tract%>% filter(GEOID==tr2_ID))
## Simple feature collection with 1 feature and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -84.29686 ymin: 33.9197 xmax: -84.28187 ymax: 33.93668
## Geodetic CRS: NAD83
## GEOID NAME variable estimate moe
## 1 13089021217 Census Tract 212.17, DeKalb County, Georgia tot_pop 2658 362
## geometry
## 1 MULTIPOLYGON (((-84.29529 3...
#------check
tract_2_bb_sfc<-st_as_sfc(tract_2_bb)
tm_shape(tract_wolkscore)+tm_borders()+
tm_fill(col="walkscore",popup.vars = "rowid")+
tm_shape(tract_2_bb_sfc)+tm_borders()
#-------no problem
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Get OSM data for the two bounding box
osm_1 <- opq(bbox = tract_1_bb) %>%
add_osm_feature(key = 'highway',
value = c("motorway", "trunk", "primary",
"secondary", "tertiary", "unclassified",
"residential")) %>%
osmdata_sf() %>%
osm_poly2line()
osm_2 <- opq(bbox = tract_2_bb) %>%
add_osm_feature(key = 'highway',
value = c("motorway", "trunk", "primary",
"secondary", "tertiary", "unclassified",
"residential")) %>%
osmdata_sf() %>%
osm_poly2line()
# =========== NO MODIFY ZONE ENDS HERE ========================================
# TASK ////////////////////////////////////////////////////////////////////////
# 1. Convert osm_1 and osm_2 to sfnetworks objects (set directed = FALSE)
# 2. Clean the network by (1) deleting parallel lines and loops, (2) create missing nodes, and (3) remove pseudo nodes,
# 3. Add a new column named length using edge_length() function.
net1 <- osm_1$osm_lines %>%
sfnetworks::as_sfnetwork(directed=FALSE)%>%
activate("edges")%>%
filter(!edge_is_multiple())%>%
filter(!edge_is_loop())%>%
convert(sfnetworks::to_spatial_subdivision)%>%
mutate(length = edge_length())
## Warning: to_spatial_subdivision assumes attributes are constant over geometries
#view-------------------
leaflet() %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView( -84.3854, 33.7668, zoom = 14) %>% # zooming in to show more details
addPolylines(data = net1 %>% st_as_sf('edges'),
col = "gray",
weight = 3,
opacity = 0.9,
popup = net1 %>% st_as_sf('edges') %>% pull(osm_id)) %>%
addCircles(data = net1 %>% st_as_sf('nodes'),
fillColor = 'yellow',
stroke = F,
radius = 20,
fillOpacity = 0.7)
#view----------------------
net2 <- osm_2$osm_lines %>%
sfnetworks::as_sfnetwork(directed=FALSE)%>%
activate("edges")%>%
filter(!edge_is_multiple())%>%
filter(!edge_is_loop())%>%
convert(sfnetworks::to_spatial_subdivision)%>%
mutate(length = edge_length())
## Warning: to_spatial_subdivision assumes attributes are constant over geometries
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# OSM for the walkable part
edges_1 <- net1 %>%
# Extract 'edges'
st_as_sf("edges") %>%
# Drop redundant columns
select(osm_id, highway, length) %>%
# Drop segments that are too short (100m)
mutate(length = as.vector(length)) %>%
filter(length > 100) %>%
# Add a unique ID for each edge
mutate(edge_id = seq(1,nrow(.)),
is_walkable = "walkable")
# OSM for the unwalkable part
edges_2 <- net2 %>%
# Extract 'edges'
st_as_sf("edges") %>%
# Drop redundant columns
select(osm_id, highway, length) %>%
# Drop segments that are too short (100m)
mutate(length = as.vector(length)) %>%
filter(length > 100) %>%
# Add a unique ID for each edge
mutate(edge_id = seq(1,nrow(.)),
is_walkable = "unwalkable")
# Merge the two
edges <- bind_rows(edges_1, edges_2)
# =========== NO MODIFY ZONE ENDS HERE ========================================
getAzi <- function(line){
# This function takes one edge (i.e., a street segment) as an input and
# outputs a data frame with four points (start, mid1, mid2, and end) and their azimuth.
# TASK ////////////////////////////////////////////////////////////////////////
# 1. From `line` object, extract the coordinates using st_coordinates() and extract the first two rows.
# 2. Use atan2() function to calculate the azimuth in degree.
# Make sure to adjust the value such that 0 is north, 90 is east, 180 is south, and 270 is west.
# 1
start_p <- line %>% st_coordinates()%>%{.[1:2,1:2]}
# 2
start_azi <- atan2(start_p[2,"X"] - start_p[1, "X"],
start_p[2,"Y"] - start_p[1, "Y"])*180/pi
# //TASK //////////////////////////////////////////////////////////////////////
# TASK ////////////////////////////////////////////////////////////////////////
# Repeat what you did above, but for last two rows (instead of the first two rows).
# Remember to flip the azimuth so that the camera would be looking at the street that's being measured
end_p <- line %>%
st_coordinates() %>%
.[(nrow(.)-1):nrow(.),1:2]
end_azi <- atan2(end_p[2,"X"] - end_p[1, "X"],
end_p[2,"Y"] - end_p[1, "Y"])*180/pi
end_azi <- if (end_azi < 180) {end_azi + 180} else {end_azi - 180}
# //TASK //////////////////////////////////////////////////////////////////////
# TASK ////////////////////////////////////////////////////////////////////////
# 1. From `line` object, use st_line_sample() function to generate points at 45%, 50% and 55% locations.
# 2. Use st_cast() function to convert 'MULTIPOINT' object to 'POINT' object.
# 3. Extract coordinates using st_coordinates().
# 4. Use the 50% location to define `mid_p` object.
# 5. Use the 45% and 55% points and atan2() function to calculate azimuth `mid_azi`.
mid_p3 <- line %>%
st_line_sample(sample = c(0.45,0.5,0.55))%>%
st_cast("POINT")%>%
st_coordinates()
mid_p <- mid_p3[2,]
mid_azi <- atan2(mid_p3[3,"X"] - mid_p3[1, "X"],
mid_p3[3,"Y"] - mid_p3[1, "Y"])*180/pi
mid_azi2 <- ifelse(mid_azi < 180, mid_azi + 180, mid_azi - 180)
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
return(tribble(
~type, ~X, ~Y, ~azi,
"start", start_p[1,"X"], start_p[1,"Y"], start_azi,
"mid1", mid_p["X"], mid_p["Y"], mid_azi,
"mid2", mid_p["X"], mid_p["Y"], mid_azi2,
"end", end_p[2,"X"], end_p[2,"Y"], end_azi))
# =========== NO MODIFY ZONE ENDS HERE ========================================
}
We can apply getAzi() function to the edges object. We
finally append edges object to make use of the columns in
edges object (e.g., is_walkable column). When
you are finished with this code chunk, you will be ready to download GSV
images.
# TASK ////////////////////////////////////////////////////////////////////////
# Apply getAzi() function to all edges.
# Remember that you need to pass edges object to st_geometry() before you apply getAzi()
endp_azi <- edges %>%
st_geometry()%>%
map_df(getAzi,.progress=T)
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
endp <- endp_azi %>%
bind_cols(edges %>%
st_drop_geometry() %>%
slice(rep(1:nrow(edges),each=4))) %>%
st_as_sf(coords = c("X", "Y"), crs = 4326, remove=FALSE) %>%
mutate(node_id = seq(1, nrow(.)))
# =========== NO MODIFY ZONE ENDS HERE ========================================
get_image <- function(iterrow){
# This function takes one row of endp and downloads GSV image using the information from endp.
# TASK ////////////////////////////////////////////////////////////////////////
# Finish this function definition.
# 1. Extract required information from the row of endp, including
# type (i.e., start, mid1, mid2, end), location, heading, edge_id, node_id, source (i.e., outdoor vs. default) and key.
# 2. Format the full URL and store it in furl.
# 3. Format the full path (including the file name) of the image being downloaded and store it in fpath
type <- iterrow$type
location <- paste(iterrow$Y%>%round(5),",",iterrow$X%>%round(5))
heading <- iterrow$azi%>%round(1)
edge_id <- iterrow$edge_id
node_id <- iterrow$node_id
key <- Sys.getenv("google_api")
furl <- glue::glue("https://maps.googleapis.com/maps/api/streetview?size=640x640&location={URLencode(location)}&heading={heading}&fov=90&pitch=0&key={key}")
fname <- glue::glue("GSV-nid_{node_id}-eid_{edge_id}-type_{type}-Location_{location}-heading_{heading}.jpg") # Don't change this code for fname
fpath <- here("downloaded_image", fname)
# //TASK //////////////////////////////////////////////////////////////////////
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Download images
if (!file.exists(fpath)){
download.file(furl, fpath, mode = 'wb')
}
# =========== NO MODIFY ZONE ENDS HERE ========================================
}
Before you download GSV images, make sure
the row number of endp is not too large! The row number of
endp will be the number of GSV images you will be
downloading. Before you download images, always double-check your Google
Cloud Console’s Billing tab to make sure that you will not go above the
free credit of $200 each month. The price is $7 per 1000 images.
# I don't want to download images all over again so I don't run this code chunk when rendering.
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Loop!
for (i in seq(472,nrow(endp))){
get_image(endp[i,])
}
# =========== NO MODIFY ZONE ENDS HERE ========================================
ZIP THE DOWNLOADED IMAGES AND NAME IT ‘gsv_images.zip’ FOR STEP 6.
Now, use Google Colab to apply the semantic segmentation model.
Merge the segmentation output to edges.
# Read the downloaded CSV file from Google Drive
seg_output <- read.csv("seg_output.csv")
# =========== NO MODIFICATION ZONE STARTS HERE ===============================
# Join the segmentation result to endp object.
seg_output_nodes <- endp %>% inner_join(seg_output, by=c("node_id"="img_id")) %>%
select(type, X, Y, node_id, building, sky, tree, road, sidewalk) %>%
mutate(across(c(building, sky, tree, road, sidewalk), function(x) x/(640*640)))
# =========== NO MODIFY ZONE ENDS HERE ========================================
At the beginning of this assignment, you defined one Census Tract as walkable and the other as unwalkable. The key to the following analysis is the comparison between walkable/unwalkable Census Tracts.
Create maps of the proportion of building, sky, tree, road, and sidewalk for walkable and unwalkable areas. In total, you will have 10 maps.
Below the maps, provide a brief description of your findings from the maps.
# TASK ////////////////////////////////////////////////////////////////////////
# Create map(s) to visualize the `pspnet_nodes` objects.
# As long as you can deliver the message clearly, you can use any format/package you want.
# divide into two groups
st_crs(tract_1_bb)=4326
st_crs(tract_2_bb)=4326
seg_output_nodes_1 <- st_crop(seg_output_nodes, tract_1_bb)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
seg_output_nodes_2 <- st_crop(seg_output_nodes, tract_2_bb)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
p1 <- c(-90, 33.8)
p2 <- c(-80, 20)
bbox1 <- c(st_point(p1) %>% st_sfc(crs = 4326),
st_point(p2) %>% st_sfc(crs = 4326)) %>% st_bbox()
bbox1_sfc<-st_as_sfc(bbox1)
p3<-c(-90,40)
p4<-c(-80,33.8)
bbox2 <- c(st_point(p3) %>% st_sfc(crs = 4326),
st_point(p4) %>% st_sfc(crs = 4326)) %>% st_bbox()
bbox2_sfc<-st_as_sfc(bbox2)
seg_output_nodes_S<-st_crop(seg_output_nodes,bbox1)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
seg_output_nodes_N<-st_crop(seg_output_nodes,bbox2)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
tm_shape(tract)+tm_borders()+
tm_shape(seg_output_nodes_N)+tm_dots()+
tm_shape(seg_output_nodes_S)+tm_dots()
#plot maps for walkable census tract
tract1<-tract%>%filter(tract$GEOID=="13121003000")
p1_building<-tm_shape(tract1)+tm_borders(col = "red")+
tm_shape(osm_1$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_S)+tm_dots(col = "building",size=0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Building Distribution")
p1_sky<-tm_shape(tract1)+tm_borders(col = "red")+
tm_shape(osm_1$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_S)+tm_dots(col = "sky",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6))+
tm_layout(title = "Sky Distribution")
p1_tree<-tm_shape(tract1)+tm_borders(col = "red")+
tm_shape(osm_1$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_S)+tm_dots(col = "tree",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Tree Distribution")
p1_road<-tm_shape(tract1)+tm_borders(col = "red")+
tm_shape(osm_1$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_S)+tm_dots(col = "road",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Road Distribution")
p1_sidewalk<-tm_shape(tract1)+tm_borders(col = "red")+
tm_shape(osm_1$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_S)+tm_dots(col = "sidewalk",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Sidewalk Distribution")
tmap_arrange(p1_building, p1_sky, p1_tree, p1_road, p1_sidewalk, ncol = 2,sync = TRUE)
## Warning: Values have found that are higher than the highest break
## Warning: Values have found that are higher than the highest break
For walkable census tract 13121003000, the proportion of building and sidewalk are relatively low. This make sense because the building will block the view of pedestrians so that decrease the walking experience of walking. The sidewalk proportion is low is propably because sidewalk itself is of small size comparing to other elements in street views. The proportion of tree, road and sky are relatively high. The road part are always of big size in street view pictures. And the trees and sky are elementes related to the walkability of the street. So the proportion of sky and tree shown in the map make sense.
#plot maps for unwalkable census tract
tract2<-tract%>%filter(tract$GEOID=="13089021217")
p2_building<-tm_shape(tract2)+tm_borders(col = "red")+
tm_shape(osm_2$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_N)+tm_dots(col = "building",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Building Distribution")
p2_sky<-tm_shape(tract2)+tm_borders(col = "red")+
tm_shape(osm_2$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_N)+tm_dots(col = "sky",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6))+
tm_layout(title = "Sky Distribution")
p2_tree<-tm_shape(tract2)+tm_borders(col = "red")+
tm_shape(osm_2$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_N)+tm_dots(col = "tree",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Tree Distribution")
p2_road<-tm_shape(tract2)+tm_borders(col = "red")+
tm_shape(osm_2$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_N)+tm_dots(col = "road",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Road Distribution")
p2_sidewalk<-tm_shape(tract2)+tm_borders(col = "red")+
tm_shape(osm_2$osm_lines)+tm_lines()+
tm_shape(seg_output_nodes_N)+tm_dots(col = "sidewalk",size = 0.01,breaks=c(0,0.1,0.2,0.3,0.4,0.5))+
tm_layout(title = "Sidewalk Distribution")
tmap_arrange(p2_building, p2_sky, p2_tree, p2_road, p2_sidewalk, ncol = 2,sync = TRUE)
## Warning: Values have found that are higher than the highest break
## Warning: Values have found that are higher than the highest break
# compare together
tmap_arrange(p1_building,p2_building,p1_sky,p2_sky,p1_tree,p2_tree,p1_road,p2_road,p1_sidewalk,p2_sidewalk,ncol = 2)
## Warning: Values have found that are higher than the highest break
## Warning: Values have found that are higher than the highest break
## Warning: Values have found that are higher than the highest break
## Warning: Values have found that are higher than the highest break
# //TASK //////////////////////////////////////////////////////////////////////
In unwalkable census tract 13089021217, compared to the first census tract, the proportion of building is lower than that of walkable tract. This may indicates that the low building proportion in street view does not 100% improves the walkability of areas. The sky proportion is slightly lower in unwalkable tract which are mostly under 0.4. However, the south-western parts of the unwalkable tract shows a high proportion of sky in street view which is not what I expected. I checked the downloaded pictures and find it’s because of some missing pictures. The south-eastern part beside it also has a high proportion of sky. it is because its a high way where few buildings are built beside the road. The proportion of trees in unwalkable tract seems slightly higher than that of walkable tract. It indicates that trees does not 100% improve the walkability of streets The proportion of road in two census tract seems no big difference. But the road in walkable tract is more dense. I guess it is because the walkable tract is more like a city where infrastructures are newer, while the unwalkable tract may be an older area.
Calculate the mean of the proportion of building, sky, tree, road, and sidewalk for walkable and unwalkable areas. In total, you will have 10 mean values.
After the calculation, provide a brief description of your findings.
# TASK ////////////////////////////////////////////////////////////////////////
# Perform the calculation as described above.
# As long as you can deliver the message clearly, you can use any format/package you want.
# For sky proportion in unwalkable census tract, some value above 0.9 seem abnormal, so I get rid of them.
sky_N<-seg_output_nodes_N%>%filter(sky<0.9)
print(paste("Building: ", mean(seg_output_nodes_S$building),mean(seg_output_nodes_N$building)))
## [1] "Building: 0.087709425105605 0.0165931542239972"
print(paste("Sky: ", mean(seg_output_nodes_S$sky),mean(sky_N$sky)))
## [1] "Sky: 0.249816699360692 0.221957842293432"
print(paste("Tree: ", mean(seg_output_nodes_S$tree),mean(seg_output_nodes_N$tree)))
## [1] "Tree: 0.177672626584075 0.242573146535389"
print(paste("Road: ", mean(seg_output_nodes_S$road),mean(seg_output_nodes_N$road)))
## [1] "Road: 0.336686610731968 0.305836213524662"
print(paste("Sidewalk: ", mean(seg_output_nodes_S$sidewalk),mean(seg_output_nodes_N$sidewalk)))
## [1] "Sidewalk: 0.0299168821822765 0.00715181265304338"
# //TASK //////////////////////////////////////////////////////////////////////
In walkable tract: mean of building and sidewalk are much higher than unwalkable tract. I think it is because walkable tract is wichin city area so there are more buildings and sidewalks. And it is no doubt that sidewalks can improve walkability. The means of sky and road in walkable census tract are slightly higher than the unwalkable The mean of tree in walkable census tract are lower than the unwalkable.
Draw box plots comparing the proportion of building, sky, tree, road, and sidewalk between walkable and unwalkable areas. Each plot presents two boxes: one for walkable areas and the other for unwalkable areas. In total, you will have 5 plots.
After the calculation, provide a brief description of your findings.
# TASK ////////////////////////////////////////////////////////////////////////
# Create box plot(s) using geom_boxplot() function from ggplot2 package.
# Use `seg_output_nodes` object to draw the box plots.
# You will find `pivot_longer` function useful.
# Combine the building, sky, tree, road, and sidewalk proportions into a single data frame
data_S <- seg_output_nodes_S %>%
select(building1="building",
sky1="sky",
tree1="tree",
road1="road",
sidewalk1="sidewalk")%>%
pivot_longer(cols = c(building1, sky1, tree1, road1, sidewalk1),
names_to = "Feature",
values_to = "Proportion")
data_N <- seg_output_nodes_N %>%
select(building2="building",
sky2="sky",
tree2="tree",
road2="road",
sidewalk2="sidewalk")%>%
pivot_longer(cols = c(building2, sky2, tree2, road2, sidewalk2),
names_to = "Feature",
values_to = "Proportion")
data_SN<-rbind(data_S,data_N)
data_building<-data_SN%>%filter(Feature %in% c("building1", "building2"))
data_sky<-data_SN%>%filter(Feature %in% c("sky1", "sky2"))
data_tree<-data_SN%>%filter(Feature %in% c("tree1", "tree2"))
data_road<-data_SN%>%filter(Feature %in% c("road1", "road2"))
data_sidewalk<-data_SN%>%filter(Feature %in% c("sidewalk1", "sidewalk2"))
# Draw box plots
ggplot(data_building, aes(x = Feature, y = Proportion)) +
geom_boxplot() +
labs(title = "Comparison of Proportions of Buiding between Walkable and Unwalkable Census Tract",
x = " Proportions of Buiding", y = "Proportion") +
scale_fill_manual(values = c("Walkable" = "blue", "Unwalkable" = "red")) +
scale_x_discrete(labels = c("building1" = "Walkable", "building2" = "Unwalkable")) +
theme_minimal()
ggplot(data_sky, aes(x = Feature, y = Proportion)) +
geom_boxplot() +
labs(title = "Comparison of Proportions of sky between Walkable and Unwalkable Census Tract",
x = "Proportions of sky", y = "Proportion") +
scale_fill_manual(values = c("Walkable" = "blue", "Unwalkable" = "red")) +
scale_x_discrete(labels = c("sky1" = "Walkable", "sky2" = "Unwalkable")) +
theme_minimal()
ggplot(data_tree, aes(x = Feature, y = Proportion)) +
geom_boxplot() +
labs(title = "Comparison of Proportions of tree between Walkable and Unwalkable Census Tract",
x = "Proportions of tree", y = "Proportion") +
scale_fill_manual(values = c("Walkable" = "blue", "Unwalkable" = "red")) +
scale_x_discrete(labels = c("tree1" = "Walkable", "tree2" = "Unwalkable")) +
theme_minimal()
ggplot(data_road, aes(x = Feature, y = Proportion)) +
geom_boxplot() +
labs(title = "Comparison of Proportions of Road between Walkable and Unwalkable Census Tract",
x = "Proportions of Road", y = "Proportion") +
scale_fill_manual(values = c("Walkable" = "blue", "Unwalkable" = "red")) +
scale_x_discrete(labels = c("road1" = "Walkable", "road2" = "Unwalkable")) +
theme_minimal()
ggplot(data_sidewalk, aes(x = Feature, y = Proportion)) +
geom_boxplot() +
labs(title = "Comparison of Proportions of Sidewalk between Walkable and Unwalkable Census Tract",
x = "Proportions of Sidewalk", y = "Proportion") +
scale_fill_manual(values = c("Walkable" = "blue", "Unwalkable" = "red")) +
scale_x_discrete(labels = c("sidewalk1" = "Walkable", "sidewalk2" = "Unwalkable")) +
theme_minimal()
# //TASK //////////////////////////////////////////////////////////////////////
The walkable census tract has apparently more proportion of building and sidewalk than that of unwalkable census tract. The proportions of sky and road of two census tract show no big difference with each other. The proportion of tree in walkable census tract is lower than unwalkable census tract The plots of road and sidewalk have many outliers, especially the proportion of sidewalk in unwalkable census tract. The box of sidewalk in unwalkable census tract are close to zero. It maybe the main reason that this census tract got a low walkscore. It can be summaried from the plots that high proportion of building and sidewalk may improve the walkability of area while the tree may not.