-
Notifications
You must be signed in to change notification settings - Fork 0
/
map
159 lines (117 loc) · 4.91 KB
/
map
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
library(dplyr)
library(ggplot2)
library(lmtest)
library(multiwayvcov)
library(tmap)
library(tigris)
data <- read.csv("atlanta_temp_3500.csv")
data$ass_sp <- (data$ass_last*2.5)/(data$salesprice)
data$tax_fmv <- data$tax_last/(data$ass_last*2.5)
data$tax_sp <- data$tax_last/(data$salesprice)
data %>%
mutate(quantile = ntile(pct_black, 4)) -> data1
data1$quantile <- as.factor(data1$quantile)
levels(data1$quantile)
#grouped boxplot
plot <- ggplot(data1, aes(x=factor(quantile), y=tax_sp, fill = S4))+
geom_boxplot()+xlab("Black % Quartile")+ylab("Tax to Sales Price")+
theme( legend.position = "none" ) + geom_smooth(method = "lm", se=FALSE, color="black", group = 1)
plot
#grouped violin plot
plot <- ggplot(data1, aes(x=factor(quantile), y=tax_fmv, fill = S4))+
geom_violin(position="dodge", alpha=0.5, outlier.colour="transparent", trim=TRUE, draw_quantiles = c(0.5))+
xlab("Black % quartile")+ylab("Tax to Fair Market Value")+
theme( legend.position = "none" )
plot
#grouped dotplot
ggplot(data1, aes(x = pct_black, y = tax_sp, colour =factor(quantile))) +
geom_point() +
stat_smooth(data=data1,
method = "lm", se = T) + xlab("Black %")+ylab("Tax to Sales Price") + theme( legend.position = "none" )
#uartile boxplot
plot <- ggplot(data1, aes(x=factor(quantile), y=tax_fmv))+
geom_boxplot()+xlab("Black % Quartile")+ylab("Fair Market Value to Sales Price")+
theme( legend.position = "none" ) + geom_smooth(method = "lm", se=FALSE, color="black", group = 1)
plot
#https://api.census.gov/data/key_signup.html
#census_api_key("590f195bf74ded3640d4b9bfe8e912ac7757ca44")
library(tidycensus)
options(tigris_use_cache = TRUE)
fulton_race <- get_decennial(
geography = "tract",
state = "GA",
county = "Fulton",
variables = c(
Hispanic = "P2_002N",
White = "P2_005N",
Black = "P2_006N",
Native = "P2_007N",
Asian = "P2_008N"),
summary_var = "P2_001N",
year = 2020,
geometry = TRUE) %>%
mutate(percent = 100 * (value / summary_value))
library(tmap)
fulton_black <- filter(fulton_race,
variable == "Black")
current.mode <- tmap_mode("plot")
tmap_mode("view")
#empty map
tm_shape(fulton_black) +
tm_polygons()
#map w/ black %
tm_shape(fulton_black) +
tm_polygons(col = "percent")
#map w/ black %
tm_shape(fulton_black) +
tm_polygons(col = "percent",
style = "quantile",
n = 5,
palette = "Purples",
title = "2020 US Census") +
tm_layout(title = "Percent Black\nby Census tract",
frame = FALSE,
legend.outside = TRUE)
#cropping area outside atlanta
df <- sf::st_as_sf(data, coords = c("lon","lat"))
fulton_black = sf::st_crop(fulton_black, xmin=-84.25, xmax=-84.60, ymin=33.62, ymax=33.90)
#map w/ black % and tax/salesprice
tm_shape(fulton_black) +
tm_polygons(col = "percent",
style = "quantile",
n = 5,
palette = "Blues",
title = "Percent Black\nby Census tract") +
tm_shape(df) + tm_bubbles(size="tax_sp", col="tax_sp", palette = "Reds", style = "quantile", legend.size.show = FALSE,
border.lwd = 0.1, border.alpha = 0.1, border.col = "black",
title.col = "Tax/Sales Price", alpha = 0.5)
#map w/ only tax/fmv
tm_shape(fulton_black) +
tm_polygons(style = "quantile",
n = 5,
palette = "Blues",
title = "2020 US Census") + tm_borders(alpha=0.4) + tm_shape(df) + tm_bubbles(size="tax_fmv", col="tax_fmv",
palette = "Reds", style = "quantile", legend.size.show = FALSE,
border.lwd = 0.1, border.alpha = 0.1, border.col = "black",
title.col = "Tax/FMV", alpha = 0.5)
df$Submarket2 <- ifelse(df$S2=="S2_1", "Submarket 1", "Submarket 2")
df$Submarket3 <- ifelse(df$S3=="S3_1", "Submarket 1", ifelse(df$S3=="S3_2", "Submarket 2", "Submarket 3"))
df$Submarket4 <- ifelse(df$S4=="S4_1", "Submarket 1", ifelse(df$S4=="S4_2", "Submarket 2", ifelse(df$S4=="S4_3", "Submarket 3", "Submarket 4")))
fulton_income <- get_acs(
geography = "tract",
state = "GA",
county = "Fulton",
variables = c(
income = "B19013_001"),
year = 2018,
geometry = TRUE)
fulton_income = sf::st_crop(fulton_income, xmin=-84.25, xmax=-84.60, ymin=33.62, ymax=33.90)
#plot submarkets overlayed on median income
tm_shape(fulton_income) +
tm_polygons(col = "estimate",
style = "quantile",
n = 5,
palette = "Blues",
title = "Median Income\nby Census tract") +
tm_shape(df) + tm_dots(col="Submarket4", size = 0.05, alpha = 0.5,
scale = 1, style = "quantile")