Census variable for median household income = “B19013_001”
ca <- get_acs(geography = "county", variables = "B19013_001", state = "CA",year = 2017)
## Getting data from the 2013-2017 5-year ACS
ca_cd <- get_acs(geography = "congressional district", variables = "B19013_001", state = "CA",year = 2017)
## Getting data from the 2013-2017 5-year ACS
ca_school <- get_acs(geography = "school district (unified)", variables = "B19013_001", state = "CA",year = 2017)
## Getting data from the 2013-2017 5-year ACS
ca_assembly <- get_acs(geography = "state legislative district (lower chamber)", variables = "B19013_001",
state = "CA",year = 2017)
## Getting data from the 2013-2017 5-year ACS
ca_senate <- get_acs(geography = "state legislative district (upper chamber)", variables = "B19013_001",
state = "CA",year = 2017)
## Getting data from the 2013-2017 5-year ACS
ca %>%
mutate(NAME = gsub(" County, California", "", NAME)) %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(color = "red", size = 2) +
labs(title = "2017 Household income by county in California",
subtitle = "Census Variable = B19013_001",
y = "",
x = "")+
#theme(text = element_text(size=10))+
theme_solarized(base_size = 8)

#ggplot(ca, aes(fill = estimate,colour="Boundary")) +
#geom_sf()+theme_void()
ca[,c(2,4)] %>%
mutate(NAME = gsub(" County, California", "", NAME)) %>%
rename(County = NAME, Median_Income = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed",full_width = F))
County
|
Median_Income
|
Alameda
|
85743
|
Alpine
|
63438
|
Amador
|
60636
|
Butte
|
46516
|
Calaveras
|
54800
|
Colusa
|
56481
|
Contra Costa
|
88456
|
Del Norte
|
41287
|
El Dorado
|
74885
|
Fresno
|
48730
|
Glenn
|
46260
|
Humboldt
|
43718
|
Imperial
|
44779
|
Inyo
|
51500
|
Kern
|
50826
|
Kings
|
49742
|
Lake
|
40446
|
Lassen
|
54083
|
Los Angeles
|
61015
|
Madera
|
48210
|
Marin
|
104703
|
Mariposa
|
51385
|
Mendocino
|
46528
|
Merced
|
46338
|
Modoc
|
39296
|
Mono
|
60595
|
Monterey
|
63249
|
Napa
|
79637
|
Nevada
|
60610
|
Orange
|
81851
|
Placer
|
80488
|
Plumas
|
50266
|
Riverside
|
60807
|
Sacramento
|
60239
|
San Benito
|
80760
|
San Bernardino
|
57156
|
San Diego
|
70588
|
San Francisco
|
96265
|
San Joaquin
|
57813
|
San Luis Obispo
|
67175
|
San Mateo
|
105667
|
Santa Barbara
|
68023
|
Santa Clara
|
106761
|
Santa Cruz
|
73663
|
Shasta
|
47258
|
Sierra
|
44190
|
Siskiyou
|
40884
|
Solano
|
72950
|
Sonoma
|
71769
|
Stanislaus
|
54260
|
Sutter
|
54347
|
Tehama
|
42512
|
Trinity
|
36563
|
Tulare
|
44871
|
Tuolumne
|
54325
|
Ventura
|
81972
|
Yolo
|
61621
|
Yuba
|
51776
|
numextract <- function(string){
str_extract(string, "\\-*\\d+\\.*\\d*")
}
ca_cd %>%
mutate(NAME = gsub(", California", "", NAME)) %>%
mutate(NAME = gsub("116th Congress", "", NAME)) %>%
mutate(NAME = gsub("Congressional", "", NAME)) %>%
mutate(NAME = numextract(NAME)) %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(color = "brown", size = 1) +
labs(title = "2017 Household income by Congressional District in California",
subtitle = "Census Variable = B19013_001",
y = "",
x = "Congressional District", caption = "Tidycensus extraction by Joe Long")+
theme_economist(base_size = 6)

ca_cd[,c(2,4)] %>%
mutate(NAME = gsub(", California", "", NAME)) %>%
mutate(NAME = gsub("116th Congress", "", NAME)) %>%
mutate(NAME = gsub("Congressional", "", NAME)) %>%
mutate(NAME = numextract(NAME)) %>%
rename(Congressional_District = NAME, Median_Income = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed",full_width = F))
Congressional_District
|
Median_Income
|
1
|
48524
|
2
|
68709
|
3
|
61268
|
4
|
72371
|
5
|
71526
|
6
|
51479
|
7
|
69964
|
8
|
50051
|
9
|
60717
|
10
|
59543
|
11
|
83343
|
12
|
97282
|
13
|
70222
|
14
|
101753
|
15
|
103109
|
16
|
40689
|
17
|
115390
|
18
|
122124
|
19
|
91357
|
20
|
66078
|
21
|
40330
|
22
|
56097
|
23
|
57341
|
24
|
67574
|
25
|
75860
|
26
|
80281
|
27
|
73445
|
28
|
62319
|
29
|
50823
|
30
|
76169
|
31
|
58167
|
32
|
64151
|
33
|
103176
|
34
|
40215
|
35
|
58467
|
36
|
46772
|
37
|
54063
|
38
|
65963
|
39
|
85147
|
40
|
43499
|
41
|
60629
|
42
|
77297
|
43
|
52806
|
44
|
49774
|
45
|
97431
|
46
|
59863
|
47
|
63887
|
48
|
87413
|
49
|
82202
|
50
|
70774
|
51
|
44759
|
52
|
89955
|
53
|
68799
|
school25top <- top_n(ca_school,n=25,estimate)
school25bottom <- top_n(ca_school,n=25,-estimate)
school25top %>%
mutate(NAME = gsub(" School District, California", "", NAME)) %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(color = "red", size = 2) +
labs(title = "2017 income by school district",
subtitle = "Top 25 districts ",
y = "",
x = "Top 25")+
theme_clean()

school25top[,c(2,4)] %>%
mutate(NAME = gsub(" School District, California", "", NAME)) %>%
rename(School_District = NAME, Median_Income = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
School_District
|
Median_Income
|
Dublin Unified
|
133410
|
Pleasanton Unified
|
137837
|
Sunol Glen Unified
|
109141
|
Manhattan Beach Unified
|
148899
|
Redondo Beach Unified
|
104548
|
Scotts Valley Unified
|
105678
|
Lammersville Joint Unified
|
119929
|
Beverly Hills Unified
|
103586
|
Cabrillo Unified
|
119777
|
Capistrano Unified
|
105704
|
Conejo Valley Unified
|
104796
|
Fremont Unified
|
122191
|
La Cañada Unified
|
173379
|
Las Virgenes Unified
|
123015
|
Livermore Valley Joint Unified
|
111654
|
Milpitas Unified
|
113087
|
Morgan Hill Unified
|
111354
|
Oak Park Unified
|
129788
|
Palo Alto Unified
|
140744
|
Palos Verdes Peninsula Unified
|
138193
|
Piedmont City Unified
|
202631
|
Poway Unified
|
110228
|
San Marino Unified
|
149427
|
San Ramon Valley Unified
|
152134
|
Santa Clara Unified
|
111722
|
school25bottom %>%
mutate(NAME = gsub(" School District, California", "", NAME)) %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(color = "blue", size = 2) +
labs(title = "2017 income by school district",
subtitle = "Bottom 25 districts",
y = "",
x = "Bottom 25")+
theme_clean()

school25bottom[,c(2,4)] %>%
mutate(NAME = gsub(" School District, California", "", NAME)) %>%
rename(School_District = NAME, Median_Income = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
School_District
|
Median_Income
|
Lucerne Valley Unified
|
26498
|
Mountain Valley Unified
|
31138
|
Mendota Unified
|
27959
|
Pacific Unified
|
35833
|
Porterville Unified
|
35608
|
Washington Unified School District (Fresno County), California
|
32312
|
Alpaugh Unified
|
30000
|
Butte Valley Unified
|
33088
|
Calipatria Unified
|
27774
|
Leggett Valley Unified
|
22375
|
Cutler-Orosi Joint Unified
|
32900
|
Death Valley Unified
|
30217
|
Klamath-Trinity Joint Unified
|
30438
|
Konocti Unified
|
30682
|
Lindsay Unified
|
32726
|
Maricopa Unified
|
32422
|
McFarland Unified
|
35422
|
Needles Unified
|
32813
|
Parlier Unified
|
31748
|
Reef-Sunset Unified
|
35121
|
Round Valley Unified
|
36495
|
San Pasqual Valley Unified
|
28214
|
Southern Trinity Joint Unified
|
25517
|
Trona Joint Unified
|
35197
|
Golden Plains Unified
|
33134
|
numextract <- function(string){
str_extract(string, "\\-*\\d+\\.*\\d*")
}
#--------------------------------
ca_assembly %>%
mutate(NAME = gsub("2018", "",NAME)) %>%
#mutate(NAME = gsub("[[:alpha:]]", "",NAME)) %>%
mutate(NAME = numextract(NAME)) %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(color = "brown", size = 1) +
labs(title = "Household income by Assembly District in California",
subtitle = "2017 American Community Survey",
y = "",
x = "Assembly Districts")+
theme_economist(base_size = 6)

ca_assembly[,c(2,4)] %>%
mutate(NAME = gsub("2018", "",NAME)) %>%
mutate(NAME = numextract(NAME)) %>%
rename(Assembly_District = NAME, Median_Income = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
Assembly_District
|
Median_Income
|
1
|
51113
|
2
|
54554
|
3
|
48540
|
4
|
64616
|
5
|
55859
|
6
|
89354
|
7
|
55231
|
8
|
55998
|
9
|
62070
|
10
|
87401
|
11
|
77083
|
12
|
61872
|
13
|
54653
|
14
|
77571
|
15
|
78849
|
16
|
128793
|
17
|
89975
|
18
|
62281
|
19
|
100065
|
20
|
88219
|
21
|
47319
|
22
|
110436
|
23
|
60364
|
24
|
124925
|
25
|
108128
|
26
|
44629
|
27
|
81366
|
28
|
119738
|
29
|
82961
|
30
|
65184
|
31
|
36105
|
32
|
40269
|
33
|
48977
|
34
|
62112
|
35
|
63891
|
36
|
54484
|
37
|
73315
|
38
|
93663
|
39
|
56454
|
40
|
59789
|
41
|
79765
|
42
|
50232
|
43
|
63051
|
44
|
87169
|
45
|
73375
|
46
|
59327
|
47
|
56145
|
48
|
65513
|
49
|
59900
|
50
|
84201
|
51
|
48777
|
52
|
58249
|
53
|
35766
|
54
|
60261
|
55
|
91213
|
56
|
42371
|
57
|
68576
|
58
|
60401
|
59
|
33752
|
60
|
69779
|
61
|
61287
|
62
|
58291
|
63
|
51400
|
64
|
47363
|
65
|
67800
|
66
|
88923
|
67
|
69715
|
68
|
93734
|
69
|
58369
|
70
|
60694
|
71
|
66200
|
72
|
70077
|
73
|
105169
|
74
|
88582
|
75
|
72692
|
76
|
73157
|
77
|
102745
|
78
|
72625
|
79
|
66909
|
80
|
48404
|
ca_senate %>%
mutate(NAME = gsub("2018", "",NAME)) %>%
mutate(NAME = numextract(NAME)) %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point(color = "darkgreen", size = 2) +
labs(title = "Household income by State Senate District in California",
subtitle = "2017 American Community Survey",
y = "",
x = "")+
theme_economist()

ca_senate[,c(2,4)] %>%
mutate(NAME = gsub("2016", "",NAME)) %>%
mutate(NAME = numextract(NAME)) %>%
rename(State_Senate_District = NAME, Median_Income = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
State_Senate_District
|
Median_Income
|
1
|
65793
|
2
|
64758
|
3
|
74297
|
4
|
54730
|
5
|
57914
|
6
|
56821
|
7
|
101749
|
8
|
58233
|
9
|
70531
|
10
|
99385
|
11
|
95110
|
12
|
49784
|
13
|
117005
|
14
|
36691
|
15
|
101756
|
16
|
53861
|
17
|
75804
|
18
|
58439
|
19
|
69232
|
20
|
57252
|
21
|
60119
|
22
|
60487
|
23
|
55529
|
24
|
42129
|
25
|
74517
|
26
|
89646
|
27
|
88580
|
28
|
61239
|
29
|
78382
|
30
|
44328
|
31
|
65296
|
32
|
66667
|
33
|
48630
|
34
|
66671
|
35
|
52817
|
36
|
87878
|
37
|
91125
|
38
|
72151
|
39
|
79023
|
40
|
53490
|