-
Notifications
You must be signed in to change notification settings - Fork 0
/
MS Tables.R
319 lines (280 loc) · 10.8 KB
/
MS Tables.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
library(tidyverse)
library(gt)
library(DescTools)
library(ggmap)
library(ggthemes)
library(plotly)
#reading in data
MS_data <- readxl::read_xlsx("point_data.xlsx")
#making categorical variables factors
MS_data <- MS_data %>%
mutate(G_T = as.factor(G_T),
HS_Program = as.factor(HS_Program),
Citywide = as.factor(Citywide))
# schools with the top percent of the pool tested
perc_tested <-
MS_data %>%
arrange(desc(perc_tested)) %>%
head(10) %>%
select(Dist, Borough, MS, total_students, testers_count, perc_tested,
total_offers, perc_tested_offered, G_T, HS_Program, Citywide) %>%
gt() %>%
# gt(groupname_col = "Borough") %>%
tab_header(
title = "Middle Schools with the Highest Percentage of\nStudents Taking the SHSAT"
) %>%
data_color(columns = perc_tested,
colors = scales::col_numeric(
palette = c(
"red", "orange", "green"
), domain = c(0, 100))
) %>%
data_color(columns = perc_tested_offered,
colors = scales::col_numeric(
palette = c(
"red", "orange", "green"
), domain = c(0, 100)
)) %>%
data_color(columns = G_T,
colors = scales::col_factor(
palette = c(SetAlpha("red", .7), SetAlpha("green", .7)),
domain = NULL, alpha = TRUE)) %>%
data_color(columns = HS_Program,
colors = scales::col_factor(
palette = c(SetAlpha("red", .7), SetAlpha("green", .7)),
domain = NULL, alpha = TRUE)) %>%
data_color(columns = Citywide,
colors = scales::col_factor(
palette = c(SetAlpha("red", .7), SetAlpha("green", .7)),
domain = NULL, alpha = TRUE)) %>%
cols_label(
Dist = "District",
MS = "Middle School",
total_students = "Total students in pool",
testers_count = "# of students tested",
perc_tested = "Percent of students tested",
total_offers = "Total offers",
perc_tested_offered = "Percent of test takers with offers",
G_T = "Gifted and Talented",
HS_Program = "High School program",
)
#gtsave(perc_tested, "TopPercTested.png", expand = 10,
# path = "Tables")
# top schools of percent of testers with offers (in color)
perc_offered_TOP_color <-
MS_data %>%
arrange(desc(perc_tested_offered)) %>%
head(10) %>%
select(Dist, Borough, MS, total_students, testers_count, perc_tested,
total_offers, perc_tested_offered, G_T, HS_Program, Citywide) %>%
gt() %>%
# gt(groupname_col = "Borough") %>%
tab_header(
title = "Middle Schools with the Highest Percentage of\nStudents Taking the SHSAT"
) %>%
data_color(columns = perc_tested,
colors = scales::col_numeric(
palette = c(
"red", "orange", "green"
), domain = c(0, 100))
) %>%
data_color(columns = perc_tested_offered,
colors = scales::col_numeric(
palette = c(
"red", "orange", "green"
), domain = c(0, 100)
)) %>%
data_color(columns = G_T,
colors = scales::col_factor(
palette = c(SetAlpha("red", .7), SetAlpha("green", .7)),
domain = NULL, alpha = TRUE)) %>%
data_color(columns = HS_Program,
colors = scales::col_factor(
palette = c(SetAlpha("red", .7), SetAlpha("green", .7)),
domain = NULL, alpha = TRUE)) %>%
data_color(columns = Citywide,
colors = scales::col_factor(
palette = c(SetAlpha("red", .7), SetAlpha("green", .7)),
domain = NULL, alpha = TRUE)) %>%
cols_label(
Dist = "District",
MS = "Middle School",
total_students = "Total students in pool",
testers_count = "# of students tested",
perc_tested = "Percent of students tested",
total_offers = "Total offers",
perc_tested_offered = "Percent of test takers with offers",
G_T = "Gifted and Talented",
HS_Program = "High School program",
)
gtsave(perc_offered_TOP_color, "TopPercOfferedColor.png", expand = 10,
path = "Tables")
MS_data %>%
arrange(desc(perc_tested_offered)) %>%
writexl::write_xlsx("top_10_offered.xlsx")
MS_data %>%
arrange(desc(perc_tested)) %>%
writexl::write_xlsx("top_10_tested.xlsx")
# top schools of percent of testers with offers
perc_offered_TOP <-
MS_data %>%
arrange(desc(perc_tested_offered)) %>%
head(10) %>%
select(Dist, Borough, MS, total_students, testers_count, perc_tested,
total_offers, perc_tested_offered, G_T, HS_Program, Citywide) %>%
gt(groupname_col = "Borough") %>%
tab_header(
title = "Middle Schools with the Highest Percentage of\nStudents Offered Spot in a Specialized School"
) %>%
cols_label(
Dist = "District",
MS = "Middle School",
total_students = "Total students in pool",
testers_count = "# of students tested",
perc_tested = "Percent of students tested",
total_offers = "Total offers",
perc_tested_offered = "Percent of test takers with offers",
G_T = "Gifted and Talented",
HS_Program = "High School program",
)
#gtsave(perc_offered_TOP, "TopPercOffered.png", expand = 10,
# path = "Desktop/TPG/Middle School/Tables/")
# lowest schools for percent of pool tested (does not include NAs)
perc_tested_LOW <-
MS_data %>%
arrange(perc_tested) %>%
head(10) %>%
select(Dist, Borough, MS, total_students, testers_count, perc_tested,
total_offers, perc_tested_offered, G_T, HS_Program, Citywide) %>%
gt(groupname_col = "Borough") %>%
tab_header(
title = "Middle Schools with the Lowest Percentage of\nStudents Taking the SHSAT"
) %>%
cols_label(
Dist = "District",
MS = "Middle School",
total_students = "Total students in pool",
testers_count = "# of students tested",
perc_tested = "Percent of students tested",
total_offers = "Total offers",
perc_tested_offered = "Percent of test takers with offers",
G_T = "Gifted and Talented",
HS_Program = "High School program",
)
#gtsave(perc_tested_LOW, "LowPercTested.png", expand = 10,
# path = "Desktop/TPG/Middle School/Tables")
# low offered
perc_offered_LOW <-
MS_data %>%
arrange(perc_tested_offered) %>%
head(10) %>%
select(Dist, Borough, MS, total_students, testers_count, perc_tested,
total_offers, perc_tested_offered, G_T, HS_Program, Citywide) %>%
gt(groupname_col = "Borough") %>%
tab_header(
title = "Middle Schools with the Lowest Percentage of\nStudents Offered Spot in a Specialized School"
) %>%
cols_label(
Dist = "District",
MS = "Middle School",
total_students = "Total students in pool",
testers_count = "# of students tested",
perc_tested = "Percent of students tested",
total_offers = "Total offers",
perc_tested_offered = "Percent of test takers with offers",
G_T = "Gifted and Talented",
HS_Program = "High School program",
)
#gtsave(perc_offered_LOW, "LowPercOffered.png", expand = 10,
# path = "Desktop/TPG/Middle School/Tables/")
# all schools with 5 or fewer students tested
tested_NA <-
MS_data %>%
filter(is.na(perc_tested)) %>%
# head(10) %>%
select(Dist, Borough, MS, total_students, testers_count, perc_tested,
total_offers, perc_tested_offered, G_T, HS_Program, Citywide) %>%
gt(groupname_col = "Borough") %>%
tab_header(
title = "Middle Schools with Five or Fewer Students Taking the SHSAT"
) %>%
cols_label(
Dist = "District",
MS = "Middle School",
total_students = "Total students in pool",
testers_count = "# of students tested",
perc_tested = "Percent of students tested",
total_offers = "Total offers",
perc_tested_offered = "Percent of test takers with offers",
G_T = "Gifted and Talented",
HS_Program = "High School program",
)
#gtsave(tested_NA, "Tested_NA.png", expand = 10,
# path = "Desktop/TPG/Middle School/Tables")
# all schools with 5 or fewer students with offers
offered_NA <-
MS_data %>%
filter(is.na(perc_tested_offered)) %>%
# head(10) %>%
select(Dist, Borough, MS, total_students, testers_count, perc_tested,
total_offers, perc_tested_offered, G_T, HS_Program, Citywide) %>%
gt(groupname_col = "Borough") %>%
tab_header(
title = "Middle Schools with Five or Fewer Students Offered Spot in a Specialized School"
) %>%
cols_label(
Dist = "District",
MS = "Middle School",
total_students = "Total students in pool",
testers_count = "# of students tested",
perc_tested = "Percent of students tested",
total_offers = "Total offers",
perc_tested_offered = "Percent of test takers with offers",
G_T = "Gifted and Talented",
HS_Program = "High School program",
)
#gtsave(offered_NA, "Offered_NA.png", expand = 10,
# path = "Desktop/TPG/Middle School/Tables")
#creating a map visualization
map_top <- MS_data %>%
arrange(desc(perc_tested)) %>%
head(10) %>%
mutate(stat = "Top 10 in percent of students tested")
map_top_temp <- MS_data %>%
arrange(desc(perc_tested_offered)) %>%
head(10) %>%
mutate(stat = "Top 10 in percent of test takers with offers")
map_top_temp2 <- MS_data %>%
filter(is.na(perc_tested)) %>%
mutate(stat = "5 or fewer students tested")
map_top_temp3 <- MS_data %>%
filter(is.na(perc_tested_offered)) %>%
mutate(stat = "5 or fewer students with offers")
map_top_all <- bind_rows(map_top, map_top_temp, map_top_temp2, map_top_temp3)
map_top <- bind_rows(map_top, map_top_temp)
map_top_geos <- geocode(map_top$MS)
map_top <- bind_cols(map_top, map_top_geos)
writexl::write_xlsx(map_top, "map_top_all.xlsx")
temp <- readxl::read_xlsx("map_top_all.xlsx")
#write_csv(temp, "map_top_all.csv")
temp <- temp %>% pivot_wider(id_cols = c(1:16, 18:19), names_from = stat, values_from = stat) %>%
mutate(Tested = `Top 10 in percent of students tested`,
Offered = `Top 10 in percent of test takers with offers`)
temp <- temp %>% mutate(stat = case_when(
is.na(Tested) ~ "Top 10: Percent of students tested",
is.na(Offered) ~ "Top 10: Percent of test takers with offers",
TRUE ~ "Top 10: Both"))
NYC_map <- get_map("New York City", zoom = 11, source = "stamen",
maptype = "toner-background")
NYC_gg <- ggmap(NYC_map) + theme_map()
NYC_gg + geom_point(data = temp, aes(lon, lat, color = stat)) +
ggtitle("Top 10 Schools in Percent of SHSAT Test Takers\nand Percent of Test Takers Offered Spots in Selective HS") +
labs(color = "Legend") +
theme(text = element_text(family = "serif", size = 12),
plot.title = element_text(hjust = 0.5))
#ggsave("top 10 map.png")
# Getting percentiles that were used to color the data in the google drive
MS_data %>% arrange(desc(perc_tested_offered))
quantile(MS_data$perc_tested_offered, na.rm = TRUE)
quantile(MS_data$perc_tested, na.rm = TRUE)
MS_data %>% dplyr::group_by(fof_testers) %>% dplyr::count(fof_testers)