-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintingNotebook.Rmd
550 lines (420 loc) · 22.3 KB
/
PrintingNotebook.Rmd
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
---
title: "Ventura QRIS Maps"
output:
html_document: default
html_notebook: default
pdf_document: default
date: "Updated April 2018"
---
```{r echo = FALSE, message = FALSE, warning = FALSE, include=FALSE}
library(tidyverse)
library(plyr)
library(readxl)
library(tigris)
library(acs)
library(stringr)
library(leaflet)
library(ggplot2)
library(tidyr)
library(ggmap)
library(sp)
library(data.table)
library(tidyverse)
## Extract all data from excel sheets into one list of df
path <- "~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/CDF_data.xlsx"
sheet_names <- excel_sheets(path)
length(sheet_names)
sheet_list <- list()
sheet_temp_list <- list()
tracker <- 1
# For this df, each 3 sheets is one set of data
for(counter in seq(from=1, to=length(sheet_names), by=3)){# process through each set of excel files
for(x in 1:3) {
sheet_temp_list[[x]] <- read_excel("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/CDF_data.xlsx", sheet=sheet_names[x+counter-1]) #read sheet into a temp sheet
if((x %% 3) == 1){ # if it is the first sheet of a new set
col_names <- colnames(sheet_temp_list[[x]]) # get the column names
} else {
colnames(sheet_temp_list[[x]]) <- col_names # apply the column names from the first sheet in a set to all other sheets in that set
}
if((x %% 3) == 0){
sheet_list[[tracker]] <- rbind.fill(sheet_temp_list) # if at the last sheet of a set, combine into one sheet and store in list
}
}
tracker <- tracker + 1 # increase number of sets stored in sheet_list by 1
}
## Merge dfs from list into single df
merge.all <- function(x, y) {
merge(x, y, all=TRUE)
}
merged_df <- Reduce(merge.all, sheet_list)
merged_df <- merged_df[-116,] # delete extra goal_dq from sheet 39
merged_df <- merged_df[-72,]
merged_df <- merged_df[-71,]
qris_all <- merged_df %>% # mutate to make site names match the names in qrisaddresses
mutate(site_name = gsub("CDR - ", "", site_name)) %>%
mutate(site_name = gsub("Cal-", "", site_name)) %>%
mutate(site_name = gsub("CDI - ", "", site_name)) %>%
mutate(site_name = gsub("CAPSLO - ", "", site_name)) %>%
mutate(site_name = gsub("SAFE ", "", site_name)) %>%
mutate(site_name = gsub("CDR/", "", site_name)) %>%
mutate(site_name = gsub("CVUSD ‐ ", "", site_name)) %>%
mutate(site_name = gsub("CVUSD - ", "", site_name)) %>%
mutate(site_name = gsub("â€", "-", site_name)) %>%
mutate(site_name = gsub("VUSD - ", "", site_name)) %>%
mutate(site_name = gsub("FCC", "Family Child Care", site_name)) %>%
mutate(site_name = gsub("HS", "High School", site_name)) %>%
mutate(site_name = ifelse(`IMPACT SIT_`==86 & site_name=="Lopez Family Child Care", "86 Lopez Family Child Care", site_name))
#
addresses <- read.csv("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/qrisaddresses.csv", header=TRUE, sep=",")
df <- merge(qris_all, addresses, by = "site_name")
#compare
final_df <- rbind(qris_all["site_name"], addresses["site_name"])
(not_shared <- distinct(final_df["site_name"],.keep_all = FALSE))
qris_exp <- qris_all %>%
mutate(`IMPACT SIT`= as.numeric(`IMPACT SIT`)) %>%
slice(1:113)
addresses_new <- addresses %>%
dplyr::rename('IMPACT SIT' = 'X') %>%
mutate(`IMPACT SIT`= as.numeric(`IMPACT SIT`))
qris_mg <- qris_exp %>%
merge(addresses_new, by = 'IMPACT SIT')
final_df <- qris_mg
#geocodes <- geocode(as.character(qris_mg$address))
#row.names(geocodes) <- row.names(final_df)
#QRSADRS <- merge(select(final_df,site_name.x),geocodes, by="row.names",all.x=TRUE)
#not_geocoded <- subset(QRSADRS, is.na(lat))
######
#write.xlsx(geocodes, "C:\\Users\\Dylan Wootton\\Desktop\\College\\Fall 2017\\Sorenson\\Data Science\\Ventura Preshool\\Preschool Project\\finalgeocodes.xlsx")
```
```{r echo = FALSE, message=FALSE, warning=FALSE, include=FALSE, results='hide'}
#### Start the geocode analysis
geocodes <- read_excel('~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/finalgeocodes1 .xlsx')
QRIS1AND2 <- subset(final_df, overallqris_trating == 1 | overallqris_trating == 2)
#QRIS2 <- subset(final_df, overallqris_trating == 2)
QRIS3 <- subset(final_df, overallqris_trating == 3)
QRIS4AND5 <- subset(final_df, overallqris_trating == 4 | overallqris_trating == 5)
#QRIS5 <- subset(final_df, overallqris_trating == 5)
colnames(geocodes)[colnames(geocodes) == 'lon'] <- 'lng'
# geocodes1 <- geocode(as.character(QRIS1$address))
# colnames(geocodes1)[colnames(geocodes1) == 'lon'] <- 'lng'
# geocodes2 <- geocode(as.character(QRIS2$address))
# colnames(geocodes2)[colnames(geocodes2) == 'lon'] <- 'lng'
# geocodes3 <- geocode(as.character(QRIS3$address))
# colnames(geocodes3)[colnames(geocodes3) == 'lon'] <- 'lng'
# geocodes4 <- geocode(as.character(QRIS4$address))
# colnames(geocodes4)[colnames(geocodes4) == 'lon'] <- 'lng'
# geocodes5 <- geocode(as.character(QRIS5$address))
# colnames(geocodes5)[colnames(geocodes5) == 'lon'] <- 'lng'
QRSADRS1 <- merge(select(QRIS1AND2,site_name.x),geocodes, by="row.names",all.x=TRUE)
#QRSADRS2 <- merge(select(QRIS2,site_name.x),geocodes, by="row.names",all.x=TRUE)
QRSADRS3 <- merge(select(QRIS3,site_name.x),geocodes, by="row.names",all.x=TRUE)
QRSADRS4 <- merge(select(QRIS4AND5,site_name.x),geocodes, by="row.names",all.x=TRUE)
#QRSADRS5 <- merge(select(QRIS5,site_name.x),geocodes, by="row.names",all.x=TRUE)
# NA_df <- rbind(subset(QRSADRS2, is.na(lat)),subset(QRSADRS3, is.na(lat)),subset(QRSADRS4, is.na(lat)),subset(QRSADRS5, is.na(lat))) # when empty, all values correctly inputted
NA_df <- rbind(subset(QRSADRS1, is.na(lat)),subset(QRSADRS3, is.na(lat)),subset(QRSADRS4, is.na(lat))) # when empty, all values correctly inputted
# noter: families under 200% the federal poverty lelve will be eligible for subsidized preschool
```
# SNAP/Food Stamps
The following map displays ACS SNAP data and QRIS rated sites.
The legend of QRIS ratings is as follows:
* Light Blue - QRIS rating of 1 or 2;
* Dark Blue - QRIS rating of 3;
* Dark Red - QRIS rating of 4 or 5.
```{r echo = FALSE, message=FALSE, warning=FALSE, results='hide'}
# public assistance income could be an option.
# B19067
counties <- c(111) # FIPS for Ventura
tracts <- tracts(state = 'CA', county = c(111), cb=TRUE)
api.key.install(key="f5076b03b081b910cd6d0cebe26ad28d2ad49454")
geo <- geo.make(state=c("CA"),
county=c(111), tract="*")
# # Fetch SNAP/Food Stamps Data
# poverty <- acs.fetch(endyear = 2015, span = 5, geography = geo,
# table.number = "B22002", col.names = "pretty")
#
# poverty_df <- data.frame(paste0(str_pad(poverty@geography$state, 2, "left", pad="0"),
# str_pad(poverty@geography$county, 3, "left", pad = "0"),
# str_pad(poverty@geography$tract, 6, "left", pad = "0")),
# poverty@estimate[,c("Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household did not receive Food Stamps/SNAP in the past 12 months:", "Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household received Food Stamps/SNAP in the past 12 months:", "Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household received Food Stamps/SNAP in the past 12 months: With children under 18 years:", "Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household received Food Stamps/SNAP in the past 12 months: With children under 18 years: Married-couple family", "Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household received Food Stamps/SNAP in the past 12 months: With children under 18 years: Other family:","Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household received Food Stamps/SNAP in the past 12 months: With children under 18 years: Other family: Male householder, no wife present", "Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household received Food Stamps/SNAP in the past 12 months: With children under 18 years: Other family: Female householder, no husband present", "Receipt of Food Stamps/SNAP by Presence of Children Under 18 Years by Household Type for Households: Household received Food Stamps/SNAP in the past 12 months: With children under 18 years: Nonfamily households")],
# stringsAsFactors = FALSE)
#
# # Selects df
# poverty_df <- select(poverty_df, 1:9)
# rownames(poverty_df)<-1:nrow(poverty_df)
# names(poverty_df)<-c("GEOID", "didnottotal", "didtotal", "wkids", "married", "otherfam", "maleonly", "femaleonly", "nonfam")
# poverty_df$percent <- 100*(poverty_df$wkids/(poverty_df$didnottotal+poverty_df$didtotal))
#
# write_rds(poverty_df, "~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/poverty_df.rds")
poverty_df <- read_rds("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/poverty_df.rds")
```
```{r, echo=FALSE, message=FALSE, warning=FALSE}
#look into toggles
# Merge
poverty_merged<- geo_join(tracts, poverty_df, "GEOID", "GEOID")
# Exclude no land tracts
poverty_merged <- poverty_merged[poverty_merged$ALAND>0,]
schooldistrictunified <- school_districts(state = 'CA', type = "elementary")
geodistrict <- geo.make(state=c("CA"),
school.district.elementary = "*")
schooldistrict <- schooldistrictunified[schooldistrictunified$GEOID %in% c("0629220"),]
# Exclude no land tracts
schooldistrict <- schooldistrict[schooldistrict$ALAND>0,]
# make the pop up
popup <- paste0("GEOID: ", poverty_merged$GEOID, "<br>", "Percent of Households w/ Children using SNAP/Food Stamps ", poverty_merged$percent)
pal <- colorNumeric(
palette = "YlGnBu",
domain = poverty_merged$percent
)
map<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = poverty_merged,
group = "SNAP",
fillColor = ~pal(percent),
color = "#b2aeae", # you need to use hex colors
fillOpacity = 0.7,
weight = 1,
smoothFactor = 0.2,
popup = popup) %>%
addPolygons(data = schooldistrict,
group = "SNAP",
color = "#ff0000", # you need to use hex colors
fillOpacity = 0,
weight = 2,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = poverty_merged$percent,
position = "bottomright",
title = "Percent of Households<br>w/ Children using SNAP/Food Stamps",
labFormat = labelFormat(suffix = "%")) %>%
# addAwesomeMarkers(QRSADRS1$lng, QRSADRS1$lat, popup = QRSADRS1$site_name.x, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'darkred')) %>%
### addAwesomeMarkers(QRSADRS1$lng, QRSADRS1$lat, popup = QRSADRS1$site_name.x, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'lightblue'))%>%
### addAwesomeMarkers(QRSADRS3$lng, QRSADRS3$lat, popup = QRSADRS3$site_name.x, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'darkblue'))%>%
### addAwesomeMarkers(QRSADRS4$lng, QRSADRS4$lat, popup = QRSADRS4$site_name.x, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'darkred'))%>%
# addAwesomeMarkers(QRSADRS5$lng, QRSADRS5$lat, popup = QRSADRS5$site_name.x,popupOptions = popupOptions(style = list("color" = "black")), icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'lightblue'))%>%
addLayersControl(
overlayGroups = c("SNAP"),
options = layersControlOptions(collapsed = FALSE))
#addMarkers(map_df$lng, map_df$lat, popup= map_df$site_name.x)
# dark red = 1, red = 2, darkblue = 3, blue = 4, light blue = 5
map
```
# % of Federal Poverty Line
The following map displays ACS % of Federal Poverty Line data and QRIS rated sites.
The legend of QRIS ratings is as follows:
* Light Blue - QRIS rating of 1 or 2;
* Dark Blue - QRIS rating of 3;
* Dark Red - QRIS rating of 4 or 5.
```{r echo = FALSE, message=FALSE, warning=FALSE, include=FALSE}
##### For Poverty 200% https://www.cde.ca.gov/sp/cd/ce/ltrgvnrapr2016.asp
# poverty <- acs.fetch(endyear = 2015, span = 5, geography = geo,
# table.number = "C17002", col.names = "pretty")
#
# attr(poverty, "acs.colnames")
#
# # Gets columns from df
# poverty_df <- data.frame(paste0(str_pad(poverty@geography$state, 2, "left", pad="0"),
# str_pad(poverty@geography$county, 3, "left", pad = "0"),
# str_pad(poverty@geography$tract, 6, "left", pad = "0")),
# poverty@estimate[,c( "Ratio of Income to Poverty Level in the Past 12 Months: Total:", "Ratio of Income to Poverty Level in the Past 12 Months: Under .50","Ratio of Income to Poverty Level in the Past 12 Months: .50 to .99","Ratio of Income to Poverty Level in the Past 12 Months: 1.00 to 1.24","Ratio of Income to Poverty Level in the Past 12 Months: 1.25 to 1.49","Ratio of Income to Poverty Level in the Past 12 Months: 1.50 to 1.84","Ratio of Income to Poverty Level in the Past 12 Months: 1.85 to 1.99" )],
# stringsAsFactors = FALSE)
#
# # Changes names of poverty_df
# rownames(poverty_df)<-1:nrow(poverty_df)
# names(poverty_df)<-c("GEOID", "Total", "50%", "100% ", "125%", "150%","185","200")
#
# poverty_df$percent <- 0
# # Calculates % below 200% of poverty rate
#
# poverty_df$percent <- 100*(((poverty_df$"50%"+poverty_df$"100%"+poverty_df$"125%"+poverty_df$"150%")/(poverty_df$"Total")))
# write_rds(poverty_df, "~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/poverty_df2.rds")
poverty_df <- read_rds("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/poverty_df2.rds")
# Merge Poverty
poverty_merged<- geo_join(tracts, poverty_df, "GEOID", "GEOID")
# Exclude useless tracts
poverty_merged <- poverty_merged[poverty_merged$ALAND>0,]
# Make popup
popup <- paste0("GEOID: ", poverty_merged$GEOID, "<br>", "Percent of Individuals Below Poverty Line", round(poverty_merged$percent,2))
pal <- colorNumeric(
palette = "YlGnBu",
domain = poverty_merged$percent
)
```
```{r echo = FALSE, message=FALSE,warning=FALSE,dpi = 92}
# Map in leaflet
map<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = poverty_merged,
fillColor = ~pal(percent),
color = "#b2aeae", # you need to use hex colors
fillOpacity = 0.7,
weight = 1,
smoothFactor = 0.2,
popup = popup,
group = "% of Poverty Line") %>%
addLegend(pal = pal,
values = poverty_merged$percent,
position = "bottomright",
title = "Percent of Households<br> Below 150% of the Poverty Line",
labFormat = labelFormat(suffix = "%")) %>%
addAwesomeMarkers(QRSADRS1$lng, QRSADRS1$lat, popup = QRSADRS1$site_name.x, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'lightblue'))%>%
addAwesomeMarkers(QRSADRS3$lng, QRSADRS3$lat, popup = QRSADRS3$site_name.x, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'darkblue'))%>%
addAwesomeMarkers(QRSADRS4$lng, QRSADRS4$lat, popup = QRSADRS4$site_name.x, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'darkred'))%>%
addLayersControl(
overlayGroups = c("% of Poverty Line"),
options = layersControlOptions(collapsed = FALSE))
map
```
# Map of Preschool Need in Ventura County As Calculated by Professor Damooie
```{r map, echo=FALSE, message=FALSE, warning=FALSE}
data <- read.csv("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/ConsultantDataFixed.csv")
data <- data[1:84,]
data$address <- paste(data$"Address..1.", data$"City", data$"State", data$"Zip", sep=" ")
# Consultant_geocodes <- geocode(as.character(data$address))
#
# ## weirdness
# Consultant_geocodes <- Consultant_geocodes %>%
# slice(1:76) %>%
# slice(-7:-8)
# write.csv(Consultant_geocodes, "~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/consultant_geocodes.csv")
Consultant_geocodes <- read_csv("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/consultant_geocodes.csv")
Consultant_geocodes <- Consultant_geocodes %>%
select(lat, lon)
Consultant_Supply <- merge(select(data,c(Site.Name,Total.supply..spaces.)),Consultant_geocodes, by="row.names",all.x=TRUE)
Consultant_Need <- merge(select(data,c(Site.Name,Total.need)),Consultant_geocodes, by="row.names",all.x=TRUE)
Consultant_Gap <- merge(select(data,c(Site.Name,Accumulated.Gap)),Consultant_geocodes, by="row.names",all.x=TRUE)
## Run from here
#write.csv(Consultant_Supply, "C:\\Users\\Dylan Wootton\\Desktop\\College\\Fall 2017\\Sorenson\\Data Science\\Ventura Preshool\\Preschool Project\\Updated_ConsultantData.csv")
#map <- get_map(location = "Ventura", zoom = 12)
# Consultant_Need <- setDT(Consultant_Need)
# Consultant_Gap <- setDT(Consultant_Gap)
#
# Consultant_Supply <- setDT(read.csv("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/Updated_ConsultantData.csv", stringsAsFactors = FALSE))
Consultant_Supply <- Consultant_Supply[1:74,]
Consultant_Need <- Consultant_Need[1:74,]
Consultant_Gap <- Consultant_Gap[1:74,]
# new_CS <- Consultant_Supply
# Consultant_Supply <- new_CS
#
# new_CS <- Consultant_Need
# Consultant_Need <- new_CS
#
# new_CS <- Consultant_Gap
# Consultant_Gap <- new_CS
##read in zipcode data because we need to add zip back in
zips <- read.csv("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/names and zipcodes.csv")
zips <- zips %>%
slice(-7:-8)
#put zipcode data back into each
Consultant_Need <- Consultant_Need %>%
mutate(Row.names = as.numeric(Row.names)) %>%
arrange(Row.names)
Consultant_Need$zip <- zips$Zip
Consultant_Supply <- Consultant_Supply %>%
mutate(Row.names = as.numeric(Row.names)) %>%
arrange(Row.names)
Consultant_Supply$zip <- zips$Zip
Consultant_Gap <- Consultant_Gap %>%
mutate(Row.names = as.numeric(Row.names)) %>%
arrange(Row.names)
Consultant_Gap$zip <- zips$Zip
## make the zip dataframe into a vector
zipdf <- zips %>%
select(Zip) %>%
distinct(Zip)
zipvec <- as.vector(zipdf)
###download the tract
#counties <- c(111) # FIPS for Ventura
options(tigris_use_cache = TRUE)
zipcodes <- zctas(cb = TRUE, starts_with = c("91", "93"))
# zipcodes <- zctas(starts_with = c("91", "93"))
# counties <- c(111) # FIPS for Ventura
# tracts <- tracts(state = 'CA', county = c(111), cb=TRUE)
Consultant_Need <- Consultant_Need %>%
mutate(ZCTA5CE10 = zip)
consult_merged<- geo_join(zipcodes, Consultant_Need, "ZCTA5CE10", "ZCTA5CE10", how="inner")
# we need to only include the salt lake county ids
##pop up makes the box when you click on a specific region, so you can label it with a name or geoid, or something else in your data
popup <- paste0("<b>", consult_merged$ZCTA5CE10, "</b><br>", "Total Need by Zipcode: ", prettyNum(round(consult_merged$Total.need,2), big.mark=","))
pal <- colorNumeric(
palette = "YlGnBu",
domain = consult_merged$Total.need
)
map33<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = consult_merged,
fillColor = ~pal(Total.need),
color = "#b2aeae", # you need to use hex colors
fillOpacity = 0.7,
weight = 1,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = consult_merged$Total.need,
position = "bottomright",
title = "Total Need by Zipcode"#,
#labFormat = labelFormat(prefix = " ")
)
map33
```
# Map of Preschool Supply in Ventura County As Calculated by Professor Damooie
```{r supply, echo=FALSE, message=FALSE}
Consultant_Supply <- Consultant_Supply %>%
mutate(ZCTA5CE10 = zip)
consult_merged2<- geo_join(zipcodes, Consultant_Supply, "ZCTA5CE10", "ZCTA5CE10", how="inner")
# we need to only include the salt lake county ids
##pop up makes the box when you click on a specific region, so you can label it with a name or geoid, or something else in your data
popup <- paste0("<b>", consult_merged2$ZCTA5CE10, "</b><br>", "Total Supply by Zipcode: ", prettyNum(round(consult_merged2$Total.supply..spaces.,2), big.mark=","))
pal <- colorNumeric(
palette = "YlGnBu",
domain = consult_merged2$Total.supply..spaces.
)
map34<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = consult_merged2,
fillColor = ~pal(Total.supply..spaces.),
color = "#b2aeae", # you need to use hex colors
fillOpacity = 0.7,
weight = 1,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = consult_merged2$Total.supply..spaces.,
position = "bottomright",
title = "Total Supply by Zipcode"#,
#labFormat = labelFormat(prefix = " ")
)
map34
```
# Map of Preschool Gap in Ventura County As Calculated by Professor Damooie
```{r gap, echo=FALSE, message=FALSE}
Consultant_Gap <- Consultant_Gap %>%
mutate(ZCTA5CE10 = zip)
Consultant_Gap <- Consultant_Gap %>%
mutate(gap = as.numeric(Accumulated.Gap))
consult_merged3<- geo_join(zipcodes, Consultant_Gap, "ZCTA5CE10", "ZCTA5CE10", how="inner")
# we need to only include the salt lake county ids
##pop up makes the box when you click on a specific region, so you can label it with a name or geoid, or something else in your data
popup <- paste0("<b>", consult_merged3$ZCTA5CE10, "</b><br>", "Total Gap by Zipcode: ", prettyNum(consult_merged3$gap), big.mark=",")
pal <- colorNumeric(
palette = "YlGnBu",
reverse = TRUE,
domain = consult_merged3$gap
)
map35<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = consult_merged3,
fillColor = ~pal(gap),
color = "#b2aeae", # you need to use hex colors
fillOpacity = 0.7,
weight = 1,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = consult_merged3$gap,
position = "bottomright",
title = "Total Gap by Zipcode"#,
#labFormat = labelFormat(prefix = " ")
)
map35
```