Var<-c("B19013_001","B25077_001")
## c(Median household Income, Median Housing Value)
ca_df <- get_acs(geography = "county",
variables = Var,
year = 2017,
survey = "acs5",
state = "06",
geometry = TRUE)
## Getting data from the 2013-2017 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================ | 24%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================= | 34%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|============================== | 44%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|===================================== | 54%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================ | 64%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|========================================================== | 84%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
ca_df1 <- get_acs(geography = "county",
variables = Var,
year = 2017,
survey = "acs5",
state = "06")
## Getting data from the 2013-2017 5-year ACS
ca_df2<-ca_df %>%
mutate(variable=case_when(
variable=="B19013_001" ~ "HHIncome",
variable=="B25077_001" ~ "HouseValue")) %>%
select(-moe) %>%
spread(variable, estimate) %>% #Spread moves rows into columns
mutate(HHInc_HousePrice_Ratio=round(HouseValue/HHIncome,2))
ca_df1[order(ca_df2$HHInc_HousePrice_Ratio),]
## # A tibble: 58 x 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 06017 El Dorado County, California B25077_001 405900 6705
## 2 06045 Mendocino County, California B25077_001 338000 8944
## 3 06025 Imperial County, California B19013_001 44779 1850
## 4 06015 Del Norte County, California B25077_001 185900 13895
## 5 06013 Contra Costa County, California B19013_001 88456 822
## 6 06015 Del Norte County, California B19013_001 41287 4114
## 7 06005 Amador County, California B25077_001 278600 7641
## 8 06057 Nevada County, California B25077_001 379800 6995
## 9 06053 Monterey County, California B25077_001 441000 6591
## 10 06023 Humboldt County, California B25077_001 285800 4628
## # ... with 48 more rows
ca_df1[rev(order(ca_df2$HHInc_HousePrice_Ratio)),]
## # A tibble: 58 x 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 06037 Los Angeles County, California B25077_001 495800 1386
## 2 06043 Mariposa County, California B25077_001 259500 14977
## 3 06041 Marin County, California B19013_001 104703 1763
## 4 06021 Glenn County, California B19013_001 46260 3402
## 5 06019 Fresno County, California B19013_001 48730 655
## 6 06053 Monterey County, California B19013_001 63249 1209
## 7 06043 Mariposa County, California B19013_001 51385 3637
## 8 06029 Kern County, California B25077_001 190600 2222
## 9 06001 Alameda County, California B19013_001 85743 940
## 10 06041 Marin County, California B25077_001 908800 8635
## # ... with 48 more rows
library(DT)
ca_dfa1 <- ca_df1[,c(2,4)]
datatable(cbind('County Name' = ca_df2[[2]],
"Price-Income Ratio" = ca_df2[[6]]) )
#datatable(ca_dfa1)
ca <- get_acs(geography = "county", variables = "B25077_001", state = "CA",year = 2017)
## Getting data from the 2013-2017 5-year ACS
ca_cd <- get_acs(geography = "congressional district", variables = "B25077_001", state = "CA",year = 2017)
## Getting data from the 2013-2017 5-year ACS
ca_school <- get_acs(geography = "school district (unified)", variables = "B25077_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 = "B25077_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 = "B25077_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 Housing value by county in California",
subtitle = "Census Variable = B25077_001",
y = "",
x = "")+
#theme(text = element_text(size=10))+
theme_solarized(base_size = 8)
#--------------------
ca1 <- get_acs(geography = "county", variables = "B25077_001", state = "CA",
year = 2017,geometry = TRUE)
## Getting data from the 2013-2017 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
ggplot(ca1, aes(fill = estimate, color = estimate)) +
geom_sf() +
scale_fill_viridis_c(labels = scales::dollar) +
scale_color_viridis_c(guide = FALSE) +
theme_minimal() +
coord_sf(crs = 26916, datum = NA) +
labs(title = "2017 Median Housing Value by county",subtitle = "California",
caption = "Data source: 2017 Census ACS by R tidycensus package.",
fill = "Price bracket")
#-----------------------
ca[,c(2,4)] %>%
mutate(NAME = gsub(" County, California", "", NAME)) %>%
rename(County = NAME, Median_Housing_Value = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed",full_width = F))
County | Median_Housing_Value |
---|---|
Alameda | 649100 |
Alpine | 343800 |
Amador | 278600 |
Butte | 238200 |
Calaveras | 273400 |
Colusa | 223600 |
Contra Costa | 522300 |
Del Norte | 185900 |
El Dorado | 405900 |
Fresno | 220600 |
Glenn | 214600 |
Humboldt | 285800 |
Imperial | 167700 |
Inyo | 243100 |
Kern | 190600 |
Kings | 185600 |
Lake | 182000 |
Lassen | 177500 |
Los Angeles | 495800 |
Madera | 220400 |
Marin | 908800 |
Mariposa | 259500 |
Mendocino | 338000 |
Merced | 196200 |
Modoc | 143100 |
Mono | 311700 |
Monterey | 441000 |
Napa | 560500 |
Nevada | 379800 |
Orange | 620500 |
Placer | 413300 |
Plumas | 228900 |
Riverside | 304500 |
Sacramento | 299900 |
San Benito | 459700 |
San Bernardino | 280200 |
San Diego | 484900 |
San Francisco | 927400 |
San Joaquin | 281100 |
San Luis Obispo | 499800 |
San Mateo | 917700 |
Santa Barbara | 509400 |
Santa Clara | 829600 |
Santa Cruz | 659900 |
Shasta | 233500 |
Sierra | 157100 |
Siskiyou | 176600 |
Solano | 342000 |
Sonoma | 513300 |
Stanislaus | 244100 |
Sutter | 234500 |
Tehama | 191400 |
Trinity | 286500 |
Tulare | 180200 |
Tuolumne | 273500 |
Ventura | 520300 |
Yolo | 370800 |
Yuba | 207100 |
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 Housing value by Congressional District in California",
subtitle = "Census Variable = B25077_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_Housing_Value = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed",full_width = F))
Congressional_District | Median_Housing_Value |
---|---|
1 | 248800 |
2 | 556100 |
3 | 296200 |
4 | 374300 |
5 | 435800 |
6 | 266700 |
7 | 330300 |
8 | 202500 |
9 | 296200 |
10 | 272000 |
11 | 586300 |
12 | 943100 |
13 | 626700 |
14 | 861600 |
15 | 663400 |
16 | 175800 |
17 | 811700 |
18 | 1115700 |
19 | 660400 |
20 | 503600 |
21 | 162000 |
22 | 235800 |
23 | 216600 |
24 | 504500 |
25 | 399700 |
26 | 523000 |
27 | 639600 |
28 | 715300 |
29 | 411400 |
30 | 608300 |
31 | 312000 |
32 | 419900 |
33 | 1077500 |
34 | 490300 |
35 | 315900 |
36 | 235100 |
37 | 633000 |
38 | 444100 |
39 | 599600 |
40 | 372700 |
41 | 285700 |
42 | 371800 |
43 | 455800 |
44 | 347800 |
45 | 661100 |
46 | 448600 |
47 | 521600 |
48 | 696600 |
49 | 647000 |
50 | 430300 |
51 | 288700 |
52 | 638900 |
53 | 456400 |
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 Housing value 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_Housing_Value = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
School_District | Median_Housing_Value |
---|---|
Pleasanton Unified | 878800 |
Sunol Glen Unified | 1043600 |
Manhattan Beach Unified | 1694900 |
Santa Barbara Unified | 949000 |
Arcadia Unified | 978100 |
Berkeley Unified | 861900 |
Beverly Hills Unified | 2000001 |
Cabrillo Unified | 881800 |
Carmel Unified | 1073700 |
Coronado Unified | 1423600 |
El Segundo Unified | 875600 |
Geyserville Unified | 944000 |
La Cañada Unified | 1341400 |
Laguna Beach Unified | 1213200 |
Las Virgenes Unified | 897200 |
Newport-Mesa Unified | 977500 |
Palo Alto Unified | 2000001 |
Palos Verdes Peninsula Unified | 1206800 |
Piedmont City Unified | 1715700 |
San Francisco Unified | 927400 |
San Marino Unified | 1498500 |
San Ramon Valley Unified | 968400 |
Santa Monica-Malibu Unified | 1289600 |
South Pasadena Unified | 928500 |
St. Helena Unified | 927700 |
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_Housing_Value = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
School_District | Median_Housing_Value |
---|---|
Cuyama Joint Unified | 119400 |
Lucerne Valley Unified | 126500 |
Washington Unified School District (Fresno County), California | 125000 |
Alpaugh Unified | 89200 |
Barstow Unified | 109000 |
Butte Valley Unified | 111800 |
Calipatria Unified | 80200 |
Corcoran Joint Unified | 124500 |
Cutler-Orosi Joint Unified | 131700 |
Death Valley Unified | 65900 |
Desert Center Unified | 77000 |
Konocti Unified | 118600 |
Laton Joint Unified | 124200 |
Maricopa Unified | 81300 |
Modoc Joint Unified | 120200 |
Mojave Unified | 101200 |
Muroc Joint Unified | 59900 |
Needles Unified | 81900 |
Palo Verde Unified | 133800 |
Reef-Sunset Unified | 127300 |
San Pasqual Valley Unified | 76200 |
Silver Valley Unified | 113300 |
Trona Joint Unified | 50600 |
Tulelake Basin Joint Unified | 83900 |
Westwood Unified | 89800 |
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 = "Housing Value 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_Housing_Value = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
Assembly_District | Median_Housing_Value |
---|---|
1 | 266300 |
2 | 380700 |
3 | 228700 |
4 | 407600 |
5 | 285300 |
6 | 431200 |
7 | 277900 |
8 | 280500 |
9 | 300000 |
10 | 726000 |
11 | 358000 |
12 | 282400 |
13 | 257600 |
14 | 429600 |
15 | 596600 |
16 | 861900 |
17 | 894200 |
18 | 513000 |
19 | 852800 |
20 | 586200 |
21 | 202000 |
22 | 967100 |
23 | 258100 |
24 | 1290300 |
25 | 723800 |
26 | 177800 |
27 | 601900 |
28 | 1007800 |
29 | 696100 |
30 | 442200 |
31 | 164700 |
32 | 158100 |
33 | 194700 |
34 | 225000 |
35 | 414200 |
36 | 225600 |
37 | 620900 |
38 | 508500 |
39 | 414500 |
40 | 323900 |
41 | 610600 |
42 | 251200 |
43 | 722800 |
44 | 558000 |
45 | 584800 |
46 | 564600 |
47 | 270500 |
48 | 414900 |
49 | 603200 |
50 | 1194400 |
51 | 475600 |
52 | 335200 |
53 | 450600 |
54 | 699100 |
55 | 613100 |
56 | 190300 |
57 | 438300 |
58 | 444800 |
59 | 330800 |
60 | 370000 |
61 | 282300 |
62 | 529200 |
63 | 382800 |
64 | 330400 |
65 | 507400 |
66 | 746100 |
67 | 324400 |
68 | 655500 |
69 | 432100 |
70 | 522700 |
71 | 410300 |
72 | 573600 |
73 | 693900 |
74 | 771700 |
75 | 439200 |
76 | 543300 |
77 | 611200 |
78 | 726500 |
79 | 425300 |
80 | 359700 |
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 = "Housing Value 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_Housing_Value = estimate) %>%
kable() %>%
kable_styling(bootstrap_options = c("hover", "condensed"))
State_Senate_District | Median_Housing_Value |
---|---|
1 | 358300 |
2 | 487200 |
3 | 417500 |
4 | 256800 |
5 | 269000 |
6 | 296300 |
7 | 633600 |
8 | 266000 |
9 | 551700 |
10 | 654700 |
11 | 871000 |
12 | 233600 |
13 | 1081900 |
14 | 156400 |
15 | 834000 |
16 | 197800 |
17 | 600600 |
18 | 469600 |
19 | 464700 |
20 | 300800 |
21 | 251200 |
22 | 462500 |
23 | 272500 |
24 | 495400 |
25 | 627500 |
26 | 996000 |
27 | 609600 |
28 | 321600 |
29 | 573500 |
30 | 476200 |
31 | 326800 |
32 | 452100 |
33 | 387900 |
34 | 532600 |
35 | 397300 |
36 | 635400 |
37 | 698800 |
38 | 466100 |
39 | 601200 |
40 | 347100 |