This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LA_Entropy_Script.R
67 lines (56 loc) · 1.71 KB
/
LA_Entropy_Script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
library(tidycensus)
library(tidyverse)
library(sf)
library(segregation)
library(mapboxapi)
library(tigris)
mapbox_token <- readLines ("H:/Mapbox/Mapbox.txt")
# Add token
mb_access_token(mapbox_token,install = TRUE)
ca_acs_data <- get_acs(
geography = "tract",
variables = c(
white = "B03002_003",
black = "B03002_004",
asian = "B03002_006",
hispanic = "B03002_012"
),
state = "CA",
geometry = TRUE,
year = 2019
)
us_urban_areas <- get_acs(
geography = "urban area",
variables = "B01001_001",
geometry = TRUE,
year = 2019,
survey = "acs1"
) %>%
filter(estimate >= 750000) %>%
transmute(urban_name = str_remove(NAME,
fixed(", CA Urbanized Area (2010)")))
ca_urban_data <- ca_acs_data %>%
st_join(us_urban_areas, left = FALSE) %>%
select(-NAME) %>%
st_drop_geometry()
la_entropy <- ca_urban_data %>%
filter(urban_name == "Los Angeles--Long Beach--Anaheim") %>%
group_by(GEOID) %>%
group_modify(~data.frame(entropy = entropy(
data = .x,
group = "variable",
weight = "estimate",
base = 4)))
la_entropy_geo <- tracts("CA", cb = TRUE, year = 2019) %>%
inner_join(la_entropy, by = "GEOID")
la_city_hall <- mb_geocode("City Hall, Los Angeles CA")
minutes_to_downtown <- mb_matrix(la_entropy_geo, la_city_hall)
la_entropy_geo$minutes <- as.numeric(minutes_to_downtown)
ggplot(la_entropy_geo, aes(x = minutes_to_downtown, y = entropy)) +
geom_point(alpha = 0.5) +
geom_smooth(method = "loess") +
theme_minimal() +
scale_x_continuous(limits = c(0, 80)) +
labs(title = "Diversity gradient, Los Angeles urbanized area",
x = "Travel-time to downtown Los Angeles in minutes, Census tracts",
y = "Entropy index")