-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapsv2.Rmd
1544 lines (1229 loc) · 69.1 KB
/
Mapsv2.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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Geospatial Analysis for First 5 Ventura County"
output:
html_document: default
html_notebook: default
pdf_document: default
date: "Updated April 2018"
---
```{r echo = FALSE, message = FALSE, warning = FALSE, include=FALSE}
library(readxl)
library(tigris)
library(acs)
library(stringr)
library(leaflet)
library(ggmap)
library(sp)
library(data.table)
library(tidyverse)
library(plyr)
#knitr::opts_chunk$set(cache=TRUE)
```
```{r echo = FALSE, message = FALSE, warning = FALSE, include=FALSE}
## 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, include=FALSE}
#### 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
```
# QRIS Rated Preschool Sites
The following map displays the QRIS rated preschool sites for Ventura County.
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}
mapq<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
# 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'))%>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
#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
mapq
```
```{r echo = FALSE, message=FALSE, warning=FALSE, include=FALSE}
# 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")
```
# SNAP/Food Stamps
The following map displays ACS data on the estimated percent of households with children who use SNAP for the tracts of Ventura County. Oxnard School District is outlined in bright red.
```{r, echo=FALSE, message=FALSE, warning=FALSE, include=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,]
```
```{r, echo=FALSE, message=FALSE, warning=FALSE}
#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 = "%")) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
#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
```
# SNAP w/ QRIS Preschools
The following map displays ACS data on the estimated percent of households with children who use SNAP for the tracts of Ventura County, with QRIS rated preschool sites as toggles overlaying the ACS data. Oxnard School District is outlined in bright red.
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}
#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'))%>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
#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
```
# Percent of Individuals below the Federal Poverty Line
The following map displays the ACS data by tract for the estimated percent of individuals in Ventura County below the Federal Poverty Line. Oxnard School District is outlined in red.
```{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") %>%
addPolygons(data = schooldistrict,
group = "% of Poverty Line",
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> Below 150% of the Poverty Line",
labFormat = labelFormat(suffix = "%")) %>%
# addLayersControl(
# overlayGroups = c("% of Poverty Line"),
# options = layersControlOptions(collapsed = FALSE)) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map
```
# Percent of Individuals below the Federal Poverty Line with QRIS Sites
The following map displays the ACS data by tract for the estimated percent of individuals in Ventura County below the Federal Poverty Line. Oxnard School District is outlined in red. data with the QRIS rated preschool sites overlaying the ACS data.
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,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") %>%
addPolygons(data = schooldistrict,
group = "% of Poverty Line",
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> 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)) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map
```
# Map of Preschool Need in Ventura County
The following map displays where the number of preschool spots needed in Ventura County by ZIP code. These numbers were calculated by Dr. Jamshid Damooei, Professor and Chair of the Economics Department at California Lutheran University.
```{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) %>%
addPolygons(data = schooldistrict,
group = "% of Poverty Line",
color = "#ff0000", # you need to use hex colors
fillOpacity = 0,
weight = 2,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = consult_merged$Total.need,
position = "bottomright",
title = "Total Need by Zipcode"#,
#labFormat = labelFormat(prefix = " ")
) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map33
```
# Map of Preschool Supply in Ventura County
The following map displays the number of preschool spots existing in Ventura County by ZIP code. These numbers were calculated by Dr. Jamshid Damooei, Professor and Chair of the Economics Department at California Lutheran University.
```{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) %>%
addPolygons(data = schooldistrict,
group = "% of Poverty Line",
color = "#ff0000", # you need to use hex colors
fillOpacity = 0,
weight = 2,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = consult_merged2$Total.supply..spaces.,
position = "bottomright",
title = "Total Supply by Zipcode"#,
#labFormat = labelFormat(prefix = " ")
) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map34
```
# Map of Preschool Gap in Ventura County
The following map displays the gap in preschool spots between the supply and demand that already exist in Ventura County by ZIP code. These numbers were calculated by Dr. Jamshid Damooei, Professor and Chair of the Economics Department at California Lutheran University.
```{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) %>%
addPolygons(data = schooldistrict,
group = "% of Poverty Line",
color = "#ff0000", # you need to use hex colors
fillOpacity = 0,
weight = 2,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = consult_merged3$gap,
position = "bottomright",
title = "Total Gap by Zipcode"#,
#labFormat = labelFormat(prefix = " ")
) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map35
```
```{r, echo=FALSE, message=FALSE}
# preschools <- read_csv("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/Child Care Centers.csv")
#
# preschools <- preschools %>%
# slice(-248)
#
# preschools <- preschools %>%
# mutate(preschooltype = ifelse(!is.na(`CDE: State Preschool`) | !is.na(`CDE: All but State Preschool`) | !is.na(`First 5`) | !is.na(`Head Start`), "Subsidized",
# ifelse(!is.na(Private), "Private", NA)))
#
# preschools %>% count('preschooltype')
#
# preschools <- preschools %>%
# select(4:6, 12)
#
# preschools <- preschools %>%
# mutate(business = `Business Name`)
#
# preschools2 <- preschools %>% # mutate to make site names match the names in qrisaddresses
# mutate(business = gsub("CDR - ", "", business)) %>%
# mutate(business = gsub("Cal-", "", business)) %>%
# mutate(business = gsub("CDI - ", "", business)) %>%
# mutate(business = gsub("CAPSLO - ", "", business)) %>%
# mutate(business = gsub("SAFE ", "", business)) %>%
# mutate(business = gsub("CDR/", "", business)) %>%
# mutate(business = gsub("CVUSD ‐ ", "", business)) %>%
# mutate(business = gsub("CVUSD - ", "", business)) %>%
# mutate(business = gsub("â€", "-", business)) %>%
# mutate(business = gsub("VUSD - ", "", business)) %>%
# mutate(business = gsub("FCC", "Family Child Care", business)) %>%
# mutate(business = gsub("MUSD", "", business)) %>%
# mutate(business = gsub("MUSD/", "", business)) %>%
# mutate(business = gsub("FUSD", "", business)) %>%
# mutate(business = gsub("FUSD", "", business)) %>%
# mutate(business = gsub("CDI/", "", business)) %>%
# mutate(business = gsub("CDR", "", business)) %>%
# mutate(business = gsub("/", " ", business))
#
# preschools2 <- preschools2 %>%
# dplyr::mutate(city = City) %>%
# dplyr::mutate(zip = Zip)
#
# preschools2 <- preschools2 %>%
# unite("address", c("business", "city", "zip"), sep = " , ")
#
# geocodes <- preschools2 %>% mutate_geocode(address)
#
# write_rds(geocodes, "~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/bigpreschoolgeocodes.rds")
geocodes <- read_rds("~/Google Drive/SI/DataScience/Side projects/Ventura Preschool /raw_data/bigpreschoolgeocodes.rds")
geosub <- geocodes %>%
filter(preschooltype=="Subsidized") %>%
filter(`Business Name`!="CDR Head Start, Oak View Center") %>%
mutate(business = `Business Name`)
geopriv <- geocodes %>%
filter(preschooltype=="Private") %>%
mutate(business = `Business Name`)
```
# Map of All Preschool Providers in Ventura County
The map below shows all of the preschools in Ventura County. Red preschools are subsidized preschools, including CDE Preschools, First 5 funded preschools, and Head Starts. The blue preschools are private preschools.
```{r echo = FALSE, message=FALSE,warning=FALSE,dpi = 92}
# Map in leaflet
map<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addAwesomeMarkers(geosub$lon, geosub$lat, popup = geosub$business, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'red'))%>%
addAwesomeMarkers(geopriv$lon, geopriv$lat, popup = geopriv$business, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'blue'))%>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map
```
# Map of Preschool Gap in Ventura County with Preschools
The following map displays the gap in preschool spots between the supply and demand that already exist in Ventura County by ZIP code. These numbers were calculated by Dr. Jamshid Damooei, Professor and Chair of the Economics Department at California Lutheran University. We've overlaid all of the preschools in Ventura County over the gaps. Red preschools are subsidized preschools, including CDE Preschools, First 5 funded preschools, and Head Starts. The blue preschools are private preschools.
```{r echo = FALSE, message=FALSE,warning=FALSE}
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) %>%
addPolygons(data = schooldistrict,
group = "% of Poverty Line",
color = "#ff0000", # you need to use hex colors
fillOpacity = 0,
weight = 2,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = consult_merged3$gap,
position = "bottomright",
title = "Total Gap by Zipcode"#,
#labFormat = labelFormat(prefix = " ")
) %>%
addAwesomeMarkers(geosub$lon, geosub$lat, popup = geosub$business, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'red'))%>%
addAwesomeMarkers(geopriv$lon, geopriv$lat, popup = geopriv$business, icon = awesomeIcons(icon = "ion-university", library = 'fa', markerColor = 'blue'))%>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map35
```
## Median Household Income in Ventura County
We used ACS data (from 2015) to map the median household income for each tract in Ventura County. Oxnard School District is outlined in red.
```{r median income, echo=FALSE, message=FALSE, warning=FALSE}
income <- acs.fetch(endyear = 2015, span = 5, geography = geo,
table.number = "B19013", col.names = "pretty")
#names(attributes(income))
# [1] "endyear" "span" "acs.units" "currency.year" "modified" "geography" "acs.colnames"
# [8] "estimate" "standard.error" "class"
#attr(income, "acs.colnames")
#convert to data.frame for merging
income_df <- data.frame(paste0(str_pad(income@geography$state, 2, "left", pad="0"),
str_pad(income@geography$county, 3, "left", pad = "0"),
str_pad(income@geography$tract, 6, "left", pad = "0")),
income@estimate[,c("B19013. Median Household Income in the Past 12 Months (in 2015 Inflation-Adjusted Dollars): Median household income in the past 12 months (in 2015 Inflation-adjusted dollars)")],
stringsAsFactors = FALSE)
income_df <- select(income_df, 1:2)
rownames(income_df)<-1:nrow(income_df)
names(income_df)<-c("GEOID", "medianincome")
#income_df$percent <- (100* (popunder5_df$threeand4/pop_df$totalpop))
##time to merge
income_merged<- geo_join(tracts, income_df, "GEOID", "GEOID", how="inner")
# we need to only include the salt lake county ids
#income_merged <- income_merged[income_merged$GEOID %in% c(4900870, 4900420, 4900360, 4900142, 4900600),]
# there are some tracts with no land that we should exclude
# pop_merged <- pop_merged[pop_merged$ALAND>0,]
##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>", income_merged$NAME, "</b><br>", "Median Household Income: ", prettyNum(round(income_merged$medianincome,2), big.mark=","))
pal <- colorNumeric(
palette = "YlGnBu",
domain = income_merged$medianincome
)
map6 <- leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = income_merged,
fillColor = ~pal(medianincome),
color = "#b2aeae", # you need to use hex colors
fillOpacity = 0.7,
weight = 1,
smoothFactor = 0.2,
popup = popup) %>%
addPolygons(data = schooldistrict,
group = "% of Poverty Line",
color = "#ff0000", # you need to use hex colors
fillOpacity = 0,
weight = 2,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = income_merged$medianincome,
position = "bottomright",
title = "Median Household Income"#,
#labFormat = labelFormat(suffix = "%")
) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map6
```
## Ethnicty in Ventura County: White Alone
We used ACS data (from 2015) to map the percent of people who marked their race/ethnicty as White: Alone for each Ventura County tract. Oxnard School District is outlined in red.
```{r white people, echo=FALSE, message=FALSE, warning=FALSE}
race <- acs.fetch(endyear = 2015, span = 5, geography = geo,
table.number = "B03002", col.names = "pretty")
#names(attributes(race))
# [1] "endyear" "span" "acs.units" "currency.year" "modified" "geography" "acs.colnames"
# [8] "estimate" "standard.error" "class"
#attr(race, "acs.colnames")
#convert to data.frame for merging
race_df <- data.frame(paste0(str_pad(race@geography$state, 2, "left", pad="0"),
str_pad(race@geography$county, 3, "left", pad = "0"),
str_pad(race@geography$tract, 6, "left", pad = "0")),
race@estimate[,c("Hispanic or Latino by Race: Total:", "Hispanic or Latino by Race: Not Hispanic or Latino: White alone", "Hispanic or Latino by Race: Hispanic or Latino:")],
stringsAsFactors = FALSE)
race_df <- select(race_df, 1:4)
rownames(race_df)<-1:nrow(race_df)
names(race_df)<-c("GEOID", "totalpop", "whitealone", "latino")
race_df$percent <- (100* (race_df$whitealone/race_df$totalpop))
##time to merge
race_merged<- geo_join(tracts, race_df, "GEOID", "GEOID", how="inner")
# we need to only include the salt lake county ids
#race_merged <- race_merged[race_merged$GEOID %in% c(4900870, 4900420, 4900360, 4900142, 4900600),]
# there are some tracts with no land that we should exclude
# pop_merged <- pop_merged[pop_merged$ALAND>0,]
##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>", race_merged$NAME, "</b><br>", "Percent White (Alone): ", prettyNum(round(race_merged$percent,2), big.mark=","))
pal <- colorNumeric(
palette = "YlGnBu",
domain = race_merged$percent
)
map7<-leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = race_merged,
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 = "% of Poverty Line",
color = "#ff0000", # you need to use hex colors
fillOpacity = 0,
weight = 2,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = race_merged$percent,
position = "bottomright",
title = "Percent White Alone",
labFormat = labelFormat(suffix = "%")
) %>%
addControl(html = "<img src = 'http://static1.squarespace.com/static/57e1fc9c20099e1414dc6070/t/588831041e5b6c469bd404ac/1495638046187/?format=200w'>", position = "topright")
map7
```
## Ethnicity in Venutra County: Hispanic/Latino
We used ACS data (from 2015) to map the percent of people who marked their race/ethnicty as Hispanci/Latino for Ventura County tract. Oxnard School District is outlined in red.
```{r hispanic/latino people, echo=FALSE, message=FALSE, warning=FALSE}
# race <- acs.fetch(endyear = 2015, span = 1, geography = geo,
# table.number = "C03002", col.names = "pretty")
#
# #names(attributes(race))
# # [1] "endyear" "span" "acs.units" "currency.year" "modified" "geography" "acs.colnames"
# # [8] "estimate" "standard.error" "class"
#
# #attr(race, "acs.colnames")
#
# #convert to data.frame for merging
# race_df <- data.frame(paste0(str_pad(race@geography$state, 2, "left", pad="0"),
# #str_pad(population@geography$county, 3, "left", pad = "0"),
# str_pad(race@geography$schooldistrictunified, 5, "left", pad = "0")),
# race@estimate[,c("Hispanic or Latino by Race: Total:", "Hispanic or Latino by Race: Not Hispanic or Latino: White alone", "Hispanic or Latino by Race: Hispanic or Latino")],
# stringsAsFactors = FALSE)
# race_df <- select(race_df, 1:4)
# rownames(race_df)<-1:nrow(race_df)
# names(race_df)<-c("GEOID", "totalpop", "whitealone", "latino")
race_df$percent <- (100* (race_df$latino/race_df$totalpop))
##time to merge
race_merged<- geo_join(tracts, race_df, "GEOID", "GEOID", how="inner")
# we need to only include the salt lake county ids
#race_merged <- race_merged[race_merged$GEOID %in% c(4900870, 4900420, 4900360, 4900142, 4900600),]
# there are some tracts with no land that we should exclude
# pop_merged <- pop_merged[pop_merged$ALAND>0,]
##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>", race_merged$NAME, "</b><br>", "Percent Hispanic/Latino: ", prettyNum(round(race_merged$percent,2), big.mark=","))