knitr::opts_chunk$set(echo = T)
library(tidyverse); library(tidycensus); library(sf); library(raster)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.1     v dplyr   1.0.6
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
## Loading required package: sp
## 
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
## 
##     select
## The following object is masked from 'package:tidyr':
## 
##     extract
library(reshape);library(tmap)
## 
## Attaching package: 'reshape'
## The following object is masked from 'package:dplyr':
## 
##     rename
## The following objects are masked from 'package:tidyr':
## 
##     expand, smiths
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(choroplethr)
## Loading required package: acs
## Loading required package: XML
## 
## Attaching package: 'acs'
## The following object is masked from 'package:dplyr':
## 
##     combine
## The following object is masked from 'package:base':
## 
##     apply
library(choroplethrMaps)
library(mapview)
## GDAL version >= 3.1.0 | setting mapviewOptions(fgb = TRUE)
library(stringr)
library(leaflet)
library(viridis)
## Loading required package: viridisLite
library(RColorBrewer)
library(censusapi)
## 
## Attaching package: 'censusapi'
## The following object is masked from 'package:methods':
## 
##     getFunction
census_api_key("dfbe50fd7620ed3bf0e87e29c6bc18ae92e8e9b0")
## To install your API key for use in future sessions, run this function with `install = TRUE`.
options(scipen = 999)
options(tigris_use_cache = TRUE)

2010 Variable

B02006_017 Estimate!!Total!!Vietnamese

B00001_001 Estimate!!Total

2019 variable

B02015_022 Estimate!!Total:!!Vietnamese

California Counties

2010 variables : B01003_001 General population

B02006_017 vietnamese population

2019 variables : B01003_001 General population

B02006_022 vietnamese population

oc10 <- get_acs(state = '06', geography =   "county", 
                  variables = c(General="B01003_001",Viet="B02006_017"), output = "wide",year = 2010) %>%
        arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
oc19 <- get_acs(state = '06', geography =   "county", 
                  variables = c(General="B01003_001",Viet="B02015_022"), output = "wide",year = 2019) %>%
        arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
oc19$general2010 <- oc10$GeneralE
oc19$viet2010 <- oc10$VietE
oc19$change <- oc19$GeneralE - oc10$GeneralE
oc19$Vchange <- oc19$VietE - oc10$VietE

oc19$NAME <- gsub(" County, California","",oc19$NAME)

oc19a <-  oc19[,c("NAME","GeneralE","VietE","Vchange")]
colnames(oc19a) <- c("County","General","Vietnamese","Change from 2010")
oc19a %>% arrange(desc(Vietnamese)) %>%
  kbl(caption = "2019 Vietnamese Population") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
  column_spec(3, bold = T, color = "blue") %>%
  column_spec(4, color = "blue") 
2019 Vietnamese Population
County General Vietnamese Change from 2010
Orange 3168044 209485 39229
Santa Clara 1927470 134164 15044
Los Angeles 10081570 93446 3015
San Diego 3316073 51824 8483
Alameda 1656754 34425 4961
Sacramento 1524553 28323 6140
Riverside 2411439 18115 1865
San Francisco 874961 15358 2047
San Bernardino 2149031 12184 -779
Contra Costa 1142251 10628 3725
San Joaquin 742603 8151 873
San Mateo 767423 4415 -102
Ventura 847263 4221 -382
Fresno 984521 3930 524
Solano 441829 3689 750
Kern 887641 2487 1198
Placer 385512 2073 907
Stanislaus 543194 2011 525
Yolo 217352 1979 -536
Sonoma 499772 1915 -518
Monterey 433410 1808 163
Santa Barbara 444829 1766 -215
Marin 259943 1098 -460
Santa Cruz 273962 776 155
San Luis Obispo 282165 676 -17
Tulare 461898 638 -399
Merced 271382 618 35
El Dorado 188563 584 487
Shasta 179212 531 179
Napa 139623 474 24
Butte 225817 443 -109
Sutter 96109 323 48
Kings 150691 299 96
Yuba 76360 275 75
Humboldt 135940 223 -129
Tehama 63912 207 57
Imperial 180701 155 32
Del Norte 27495 127 51
San Benito 60376 93 -41
Madera 155433 78 31
Mendocino 87224 58 -174
Calaveras 45514 53 32
Lake 64195 45 45
Lassen 30818 39 -50
Mono 14310 28 28
Colusa 21454 23 -3
Inyo 17977 16 16
Trinity 12700 16 -21
Nevada 99244 15 -143
Amador 38429 12 -51
Mariposa 17420 10 10
Alpine 1039 5 -18
Tuolumne 54045 5 -33
Plumas 18660 4 4
Glenn 27976 0 -72
Modoc 8907 0 -3
Sierra 3040 0 0
Siskiyou 43468 0 -88

Assembly Districts

oc10 <- get_acs(state = '06',  geography =   "state legislative district (lower chamber)", 
                  variables = c(General="B01003_001",Viet="B02006_017"), output = "wide",year = 2010) %>%
        arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
oc19 <- get_acs(state = '06',  geography =   "state legislative district (lower chamber)", 
                  variables = c(General="B01003_001",Viet="B02015_022"), output = "wide",year = 2019) %>%
        arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
oc19$change <- oc19$GeneralE - oc10$GeneralE
oc19$Vchange <- oc19$VietE - oc10$VietE

oc19$NAME <- gsub(", California","",oc19$NAME) 
oc19$NAME <- gsub("2018","",oc19$NAME)
oc19$NAME <- gsub("[[:punct:]]","",oc19$NAME)

oc19[,c(2,5,8)] %>% arrange(desc(VietE)) %>%
  kbl(caption = "2019 Vietnamese Population") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
  column_spec(2, bold = T, color = "blue") %>%
  column_spec(3, color = "blue") 
2019 Vietnamese Population
NAME VietE Vchange
Assembly District 72 120193 110493
Assembly District 27 74837 71952
Assembly District 25 41943 40624
Assembly District 49 27640 -1414
Assembly District 65 26640 23902
Assembly District 69 26033 -3885
Assembly District 77 20003 17799
Assembly District 9 15367 9056
Assembly District 68 15211 -71719
Assembly District 74 13464 9447
Assembly District 18 12904 3755
Assembly District 79 12793 10788
Assembly District 20 12437 -6457
Assembly District 28 9882 -1226
Assembly District 48 9411 8075
Assembly District 19 8679 5840
Assembly District 17 7953 5271
Assembly District 13 7657 2322
Assembly District 45 7451 3899
Assembly District 8 7326 2917
Assembly District 29 6888 4666
Assembly District 55 6884 3023
Assembly District 80 6141 5589
Assembly District 60 5981 112
Assembly District 66 5806 888
Assembly District 15 5478 -634
Assembly District 52 5474 4621
Assembly District 67 5430 -12958
Assembly District 75 5368 -9223
Assembly District 24 5214 -16830
Assembly District 7 5114 2049
Assembly District 16 4878 -3556
Assembly District 57 4711 -2301
Assembly District 14 4684 1238
Assembly District 73 4338 1283
Assembly District 40 3959 -2388
Assembly District 11 3894 160
Assembly District 76 3873 -4369
Assembly District 62 3811 1335
Assembly District 78 3662 -6841
Assembly District 51 3511 -917
Assembly District 61 3456 -1888
Assembly District 38 3357 661
Assembly District 6 3266 1030
Assembly District 58 3205 1347
Assembly District 23 3146 -55238
Assembly District 30 2921 2480
Assembly District 41 2857 1345
Assembly District 22 2658 -12218
Assembly District 70 2642 -10853
Assembly District 54 2557 -424
Assembly District 4 2471 709
Assembly District 37 2136 138
Assembly District 47 2129 -28
Assembly District 63 2115 -2595
Assembly District 44 2107 -2330
Assembly District 43 2071 193
Assembly District 46 1947 1311
Assembly District 12 1860 -6685
Assembly District 10 1859 -8929
Assembly District 50 1810 863
Assembly District 34 1805 772
Assembly District 64 1615 -3445
Assembly District 39 1504 -212
Assembly District 53 1436 -1623
Assembly District 2 1380 414
Assembly District 42 1377 -176
Assembly District 35 1266 -2034
Assembly District 71 1249 -8076
Assembly District 3 1248 249
Assembly District 21 1170 -2606
Assembly District 36 982 -938
Assembly District 32 952 -183
Assembly District 56 895 -3810
Assembly District 33 844 -282
Assembly District 31 822 -318
Assembly District 1 651 -231
Assembly District 26 616 -2620
Assembly District 59 556 -1092
Assembly District 5 483 -2553

Senate Districts

oc10 <- get_acs(state = '06',  geography =   "state legislative district (upper chamber)", 
                  variables = c(General="B01003_001",Viet="B02006_017"), output = "wide",year = 2010) %>%
        arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
oc19 <- get_acs(state = '06',  geography =   "state legislative district (upper chamber)", 
                  variables = c(General="B01003_001",Viet="B02015_022"), output = "wide",year = 2019) %>%
        arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
oc19$change <- oc19$GeneralE - oc10$GeneralE
oc19$Vchange <- oc19$VietE - oc10$VietE

oc19$NAME <- gsub(", California","",oc19$NAME) 
oc19$NAME <- gsub("2018","",oc19$NAME)
oc19$NAME <- gsub("[[:punct:]]","",oc19$NAME)

oc19[,c(2,5,8)] %>% arrange(desc(VietE)) %>%
  kbl(caption = "2019 Vietnamese American Population") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
   column_spec(2, bold = T, color = "blue") %>%
  column_spec(3, color = "blue") 
2019 Vietnamese American Population
NAME VietE Vchange
State Senate District 34 144963 53766
State Senate District 15 81899 74714
State Senate District 10 49935 8555
State Senate District 22 38613 32282
State Senate District 29 33322 24498
State Senate District 37 28892 20028
State Senate District 39 27689 6122
State Senate District 6 24188 12339
State Senate District 9 18424 5491
State Senate District 17 17263 14163
State Senate District 11 16620 -170
State Senate District 27 11209 4893
State Senate District 38 10503 31
State Senate District 5 10066 -3104
State Senate District 40 9899 5032
State Senate District 31 9437 722
State Senate District 7 9316 3055
State Senate District 35 9188 -45878
State Senate District 36 8226 -1916
State Senate District 32 8201 310
State Senate District 13 7824 -66584
State Senate District 28 7756 2494
State Senate District 20 7603 157
State Senate District 3 6604 -889
State Senate District 26 5402 2555
State Senate District 23 5081 -333
State Senate District 4 5068 2584
State Senate District 24 4924 -23266
State Senate District 25 4806 -2447
State Senate District 8 4290 -7324
State Senate District 18 3980 1618
State Senate District 33 3611 -16540
State Senate District 19 3439 -1633
State Senate District 2 3083 -1107
State Senate District 1 3000 -6164
State Senate District 16 2322 665
State Senate District 21 2269 -8091
State Senate District 30 2016 -1957
State Senate District 14 1719 -1858
State Senate District 12 1694 -302

Congressional Districts

oc10 <- get_acs(state = '06',  geography =   "congressional district", 
                  variables = c(General="B01003_001",Viet="B02006_017"), output = "wide",year = 2010) %>%
        arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
oc19 <- get_acs(state = '06',  geography =   "congressional district", 
                  variables = c(General="B01003_001",Viet="B02015_022"), output = "wide",year = 2019) %>%
        arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
oc19$change <- oc19$GeneralE - oc10$GeneralE
oc19$Vchange <- oc19$VietE - oc10$VietE

oc19$NAME <- gsub("116th Congress","",oc19$NAME) 
oc19$NAME <- gsub(", California","",oc19$NAME) 
oc19$NAME <- gsub("[[:punct:]]","",oc19$NAME)


oc19[,c(2,5,8)] %>% arrange(desc(VietE)) %>%
  kbl(caption = "2019 Vietnamese American Population") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
   column_spec(2, bold = T, color = "blue") %>%
  column_spec(3, color = "blue") 
2019 Vietnamese American Population
NAME VietE Vchange
Congressional District 19 82836 80683
Congressional District 48 75925 59549
Congressional District 47 64334 1815
Congressional District 17 46607 44379
Congressional District 46 43295 -12878
Congressional District 27 21887 15302
Congressional District 52 21124 14212
Congressional District 45 19893 14936
Congressional District 7 18409 12975
Congressional District 32 18295 -5455
Congressional District 15 15179 -25965
Congressional District 13 14780 -3669
Congressional District 12 13073 6800
Congressional District 53 11517 -2320
Congressional District 39 10616 6676
Congressional District 18 10326 8051
Congressional District 42 10039 2084
Congressional District 51 9845 4131
Congressional District 6 9829 5962
Congressional District 30 9285 5363
Congressional District 43 8470 4257
Congressional District 9 8382 -733
Congressional District 38 7548 1121
Congressional District 11 7024 -1878
Congressional District 35 6362 1414
Congressional District 14 6230 -593
Congressional District 49 5557 721
Congressional District 41 5479 2296
Congressional District 50 5308 -9058
Congressional District 31 4956 1026
Congressional District 3 4922 -6219
Congressional District 5 4807 -6220
Congressional District 34 4397 2136
Congressional District 33 3986 2149
Congressional District 22 3394 1956
Congressional District 10 3128 -1281
Congressional District 26 3118 -4015
Congressional District 28 2856 155
Congressional District 25 2824 -327
Congressional District 20 2806 1689
Congressional District 4 2706 1021
Congressional District 29 2619 -10946
Congressional District 37 2579 -2750
Congressional District 24 2443 -529
Congressional District 44 2235 -6834
Congressional District 36 2150 -1438
Congressional District 23 2107 -1862
Congressional District 2 2059 307
Congressional District 8 1695 -9053
Congressional District 16 1645 -69366
Congressional District 1 1275 -2474
Congressional District 40 1121 -28909
Congressional District 21 1062 -1883

Zip codes : zcta

only 2019 data with zip code divisions are available

Population by California zip codes

zip19 <- get_acs( geography =   "zcta", 
                  variables = "B02015_022", year = 2019) %>%
        arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
zip19$NAME <- as.numeric(gsub("ZCTA5","",zip19$NAME))

cazip <- zip19 %>% filter(NAME>90000 & NAME<96000)  
cazip <- cazip[,c(2,4)]
colnames(cazip) <- c("Zipcode","Population")



top_n(cazip,n=100,Population) %>% arrange(desc(Population)) %>%
  kbl(caption = "Top 100 Vietnamese Population by zip codes in California") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
  column_spec(1:2,  color = "blue") 
Top 100 Vietnamese Population by zip codes in California
Zipcode Population
92683 37293
92843 17880
95111 15609
92840 13251
92708 12508
95121 12244
92704 12159
92841 12045
95148 11361
92844 11265
95122 10557
95035 10225
92804 9809
92703 9692
92126 8768
95132 8635
91770 7864
90680 6453
95127 6354
95133 6288
95112 5872
92105 5659
95116 4933
95131 4901
95136 4704
91732 4317
95624 4265
95828 4122
92655 4061
92115 3867
91733 3833
95123 3812
92647 3533
92802 3305
94606 3147
92111 3064
92646 3010
91776 2921
95138 2865
92801 2751
94587 2646
92129 2577
92706 2553
91801 2515
95757 2506
95829 2440
94544 2379
91731 2351
92648 2280
95823 2279
95209 2243
91706 2163
92626 2130
92806 2120
95758 2115
91335 2085
91306 2048
92563 2048
91790 2006
90260 1918
94538 1909
94122 1907
95135 1893
92620 1892
94501 1863
92707 1842
94577 1721
92602 1697
94112 1684
92805 1585
92503 1568
95051 1565
94568 1560
95037 1549
92127 1526
92117 1490
94560 1478
95212 1467
94134 1415
90031 1414
95824 1386
94565 1382
91754 1378
94539 1351
92630 1349
90620 1346
94536 1331
94601 1322
91763 1310
92618 1304
92780 1302
94806 1277
94541 1273
91304 1258
92886 1242
95125 1236
94089 1222
91007 1219
91744 1218
92124 1216

Population by Santa Clara County zip codes ( from 94022 to 95173)

sczip <- cazip %>% filter(Zipcode>94020 & Zipcode <95180)

top_n(sczip,n=100,Population) %>% arrange(desc(Population)) %>%
  kbl(caption = "Top 100 Vietnamese Population by zip codes in Santa Clara County") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
  column_spec(1:2,  color = "blue") 
Top 100 Vietnamese Population by zip codes in Santa Clara County
Zipcode Population
95111 15609
95121 12244
95148 11361
95122 10557
95035 10225
95132 8635
95127 6354
95133 6288
95112 5872
95116 4933
95131 4901
95136 4704
95123 3812
94606 3147
95138 2865
94587 2646
94544 2379
94538 1909
94122 1907
95135 1893
94501 1863
94577 1721
94112 1684
95051 1565
94568 1560
95037 1549
94560 1478
94134 1415
94565 1382
94539 1351
94536 1331
94601 1322
94806 1277
94541 1273
95125 1236
94089 1222
95128 1210
95050 1160
94545 1149
94102 1064
95124 1064
94555 1055
95134 1052
95008 1037
95117 1027
94579 1016
94533 1002
94124 993
95120 988
95118 979
95014 959
94121 925
95054 894
94116 878
94109 869
94547 790
94580 787
94118 776
95129 773
94578 728
94085 698
95020 693
94531 664
94115 632
94132 603
94551 601
94591 593
94546 586
94080 579
95119 578
94520 571
94804 555
94553 553
94582 552
94086 535
94901 534
94127 533
95126 529
94602 499
94585 482
94509 478
94704 475
94103 451
94803 445
94087 442
94589 405
94621 400
94040 398
94603 393
94605 390
94114 387
94110 385
94607 382
94117 371
94502 368
95070 367
94609 356
95139 351
94619 330
94107 329

Population by Orange County zip codes ( from 90620 to 92899)

oczip <- cazip %>% filter(Zipcode>90600 & Zipcode <92900)

top_n(oczip,n=100,Population) %>% arrange(desc(Population)) %>%
  kbl(caption = "Top 100 Vietnamese Population by zip codes in Orange County") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
  column_spec(1:2,  color = "blue") 
Top 100 Vietnamese Population by zip codes in Orange County
Zipcode Population
92683 37293
92843 17880
92840 13251
92708 12508
92704 12159
92841 12045
92844 11265
92804 9809
92703 9692
92126 8768
91770 7864
90680 6453
92105 5659
91732 4317
92655 4061
92115 3867
91733 3833
92647 3533
92802 3305
92111 3064
92646 3010
91776 2921
92801 2751
92129 2577
92706 2553
91801 2515
91731 2351
92648 2280
91706 2163
92626 2130
92806 2120
91335 2085
91306 2048
92563 2048
91790 2006
92620 1892
92707 1842
92602 1697
92805 1585
92503 1568
92127 1526
92117 1490
91754 1378
92630 1349
90620 1346
91763 1310
92618 1304
92780 1302
91304 1258
92886 1242
91007 1219
91744 1218
92124 1216
92869 1213
92782 1188
90650 1181
92649 1171
92123 1167
92612 1159
92606 1148
92870 1144
90703 1139
91755 1135
91766 1132
90630 1108
92131 1081
91780 1078
92879 1060
92880 1049
92656 1007
92705 982
92102 973
92882 968
92064 967
90805 966
92845 962
92069 923
92614 923
91709 909
92867 909
91311 900
92354 896
92507 886
91803 870
91791 868
92505 860
92027 830
92078 775
92604 773
92868 754
92596 753
92336 738
92122 736
92603 723
92865 715
90621 712
91745 706
91343 692
90706 685
91710 683

Population by Alameda County zip codes ( from 94501 to 94712)

alzip <- cazip %>% filter(Zipcode>94500 & Zipcode <94713)

top_n(alzip,n=75,Population) %>% arrange(desc(Population)) %>%
  kbl(caption = "Top 75 Vietnamese Population by zip codes in Alameda County") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
  column_spec(1:2,  color = "blue") 
Top 75 Vietnamese Population by zip codes in Alameda County
Zipcode Population
94606 3147
94587 2646
94544 2379
94538 1909
94501 1863
94577 1721
94568 1560
94560 1478
94565 1382
94539 1351
94536 1331
94601 1322
94541 1273
94545 1149
94555 1055
94579 1016
94533 1002
94547 790
94580 787
94578 728
94531 664
94551 601
94591 593
94546 586
94520 571
94553 553
94582 552
94602 499
94585 482
94509 478
94704 475
94589 405
94621 400
94603 393
94605 390
94607 382
94502 368
94609 356
94619 330
94610 325
94542 316
94608 302
94564 295
94550 280
94566 276
94534 264
94703 262
94583 246
94558 237
94521 228
94595 215
94523 210
94503 205
94549 204
94611 203
94563 194
94506 188
94513 183
94552 161
94597 155
94561 144
94588 142
94510 137
94709 136
94519 129
94526 128
94702 114
94598 110
94706 105
94518 89
94592 83
94530 81
94705 70
94596 64
94618 62

Population by San Diego County zip codes ( from 91901 to 92199)

sdzip <- cazip %>% filter(Zipcode>91900 & Zipcode <92200)

top_n(sdzip,n=75,Population) %>% arrange(desc(Population)) %>%
  kbl(caption = "Top 75 Vietnamese Population by zip codes in San Diego County") %>%
  kable_classic(full_width = F, html_font = "Cambria")    %>%
  column_spec(1:2,  color = "blue") 
Top 75 Vietnamese Population by zip codes in San Diego County
Zipcode Population
92126 8768
92105 5659
92115 3867
92111 3064
92129 2577
92127 1526
92117 1490
92124 1216
92123 1167
92131 1081
92102 973
92064 967
92069 923
92027 830
92078 775
92122 736
92026 682
92058 668
92114 656
92128 639
92056 631
92120 623
92130 613
91941 540
91945 539
92104 498
92010 466
91913 443
92011 443
92025 419
91902 393
92154 390
91911 363
92009 361
92139 339
92119 334
92083 295
91942 294
92014 276
92057 271
92081 268
92082 255
92071 243
91950 238
92116 236
92029 231
91977 221
92121 210
92101 208
92113 207
92109 204
92021 188
92110 182
92020 180
91910 168
92024 157
91914 140
92065 122
92107 121
92054 114
92019 110
91915 108
92037 104
92084 85
92108 82
92055 67
92075 66
92103 66
91935 56
91978 52
92106 51
92008 39
91932 38
92040 38
92118 36