Total = student population ( public and private) from

pre-school to graduate/professional/vocational schools

ca_education <- get_acs(geography = "congressional district",
                   variables = "B14002_001",
                   year = 2018,
                   survey = "acs5",
                   state = "06")
## Getting data from the 2014-2018 5-year ACS
ca_cd <- us_congressional(resolution = "high",states = "California")
ca_cd <- arrange(ca_cd,geoid)
ca_cd$count <- ca_education$estimate                   


ggplot(ca_cd) + geom_sf(aes(fill = count)) +
  scale_fill_gradientn(colors = rev(magma(5)))+
  labs(title = "Student population by California Congressional District",
       subtitle = "2018 Census data : B14002_001 ")+
  theme_void()

Student population by Congressional Districts

library(stringr)
numextract <- function(string){ 
  str_extract(string, "\\-*\\d+\\.*\\d*")
} 

 ca_education[,c(2,4)] %>%
   mutate(NAME = gsub("116th", "", NAME)) %>%
  mutate(NAME = numextract(NAME)) %>% 
  rename(Congressional_District = NAME, count = estimate)  %>%
  kable() %>%
  kable_styling(bootstrap_options = c("hover", "condensed",full_width = F))
Congressional_District count
1 684653
2 697528
3 709990
4 714030
5 704142
6 719349
7 720742
8 689082
9 729034
10 713485
11 728665
12 733548
13 729305
14 729592
15 745556
16 691093
17 742382
18 716662
19 731920
20 706611
21 679438
22 721944
23 708381
24 709277
25 690191
26 700236
27 695300
28 696279
29 694642
30 739127
31 712823
32 694365
33 692772
34 703045
35 712771
36 718088
37 699148
38 690531
39 702024
40 680616
41 722137
42 764173
43 696142
44 692081
45 746445
46 698754
47 690026
48 704402
49 709498
50 718555
51 699358
52 738641
53 739381
ca_education[,c(2,4)] %>%
  mutate(NAME = gsub("2018", "",NAME)) %>% 
   mutate(NAME = numextract(NAME)) %>% 
   ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
   geom_point(color = "brown", size = 1) +
  labs(title = "Student Population by Congressional Districts in California",
       subtitle = "",
       y = "Congressional District ",
       x = "Student count")+
  theme_economist(base_size = 6.5)  

county <- get_acs(geography = "county",
                   variables = "B14002_001",
                   year = 2018,
                   survey = "acs5", geometry = T,
                   state = "06")
## Getting data from the 2014-2018 5-year ACS
ggplot(county) + geom_sf(aes(fill = estimate)) +
  scale_fill_gradientn(colors = rev(magma(5)))+
  labs(title = "Student Population by County",
       subtitle = "2018 Census data : B14002_001 ")+
  theme_void()

## Student Population by State Senate Districts

ca_senate <- get_acs(geography = "state legislative district (upper chamber)", 
                     variables = "B14002_001",   survey = "acs5",
                       state = "CA",year = 2018)
## Getting data from the 2014-2018 5-year ACS
ca_senate %>%
   mutate(NAME = gsub("2018", "",NAME)) %>% 
   mutate(NAME = numextract(NAME)) %>% 
  
   ggplot(aes(x = estimate, y = reorder(NAME,estimate ))) +
 
  geom_point(color = "brown", size = 1) +
  labs(title = "Student Population by State Senate District in California",
       subtitle = "2018 Census Variable = B14002_001",  
       y = "",
       x = "Student", caption = "Tidycensus extraction by Joe Long")+
  theme_economist(base_size = 7)

ca_senate[,c(2,4)] %>%
   mutate(NAME = gsub("2018", "",NAME)) %>% 
   mutate(NAME = numextract(NAME)) %>% 
  rename(Senate_District = NAME, Student_count = estimate) %>%
  kable() %>%
  kable_styling(bootstrap_options = c("hover", "condensed",full_width = F))
Senate_District Student_count
1 927412
2 920271
3 941911
4 946429
5 958221
6 963693
7 986839
8 946494
9 972948
10 978103
11 973293
12 927224
13 958191
14 899920
15 948393
16 923306
17 952335
18 931224
19 931396
20 947956
21 918976
22 919112
23 959804
24 919382
25 920902
26 925347
27 952584
28 977668
29 924124
30 921151
31 970986
32 916611
33 897754
34 923303
35 919920
36 953112
37 977983
38 946229
39 968751
40 948702

Student Population by State Assembly Districts

ca_assembly <- get_acs(geography = "state legislative district (lower chamber)", 
                     variables = "B14002_001",   survey = "acs5",
                       state = "CA",year = 2018)
## Getting data from the 2014-2018 5-year ACS
ca_assembly %>%
   mutate(NAME = gsub("2018", "",NAME)) %>% 
   mutate(NAME = numextract(NAME)) %>% 
  
   ggplot(aes(x = estimate, y = reorder(NAME,estimate ))) +
 
  geom_point(color = "brown", size = 1) +
  labs(title = "Student Population by Assembly District in California",
       subtitle = "2018 Census Variable = B14002_001",  
       y = "",
       x = "Student", caption = "Tidycensus extraction by Joe Long")+
  theme_economist(base_size = 7)

ca_assembly[,c(2,4)] %>%
   mutate(NAME = gsub("2018", "",NAME)) %>% 
   mutate(NAME = numextract(NAME)) %>% 
  rename(Assembly_District = NAME, Student_count = estimate) %>%
  kable() %>%
  kable_styling(bootstrap_options = c("hover", "condensed",full_width = F))
Assembly_District Student_count
1 446262
2 453457
3 461581
4 468534
5 450881
6 496137
7 473721
8 476081
9 480635
10 470315
11 490616
12 474488
13 471330
14 481775
15 484602
16 499689
17 485427
18 486225
19 491593
20 479254
21 459339
22 479440
23 487049
24 479651
25 496880
26 463879
27 479332
28 472630
29 473102
30 470937
31 451537
32 451523
33 458651
34 476541
35 472853
36 453965
37 471253
38 466776
39 454806
40 469750
41 458402
42 478577
43 464216
44 456035
45 492254
46 475386
47 473008
48 457141
49 457728
50 466933
51 454132
52 474948
53 465730
54 462300
55 461427
56 455378
57 460953
58 456102
59 462540
60 490266
61 480720
62 458163
63 447275
64 467275
65 459698
66 457495
67 510015
68 484948
69 460730
70 459002
71 467933
72 470626
73 468190
74 488789
75 486035
76 476123
77 491322
78 467240
79 501476
80 458952