v10 <- load_variables(2010, "acs5", cache = TRUE)
View(v10)
v19 <- load_variables(2019, "acs5", cache = TRUE)



salvadoran19 <- v19 %>%
  filter(str_detect(label,pattern="Salvadoran"))
salvadoran10 <- v10 %>%
  filter(str_detect(label,pattern="Salvadoran"))

B03001_014 Estimate!!Total:!!Hispanic or Latino:!!Central American:!!Salvadoran

sal2019 <- get_acs(geography = "state",variables = "B03001_014",
                    year = 2019,geometry = F) %>%
             arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
sal2010 <- get_acs(geography = "state",variables = "B03001_014",
                    year = 2010,geometry = F) %>%
             arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
names(sal2019)[4] <- "year2019"
sal2019$year2010 <- sal2010$estimate
sal2019$change <- sal2019$year2019 - sal2019$year2010

sal2019[,c(2,4,6,7)] %>% arrange(desc(year2019)) %>%
  kbl(caption = "Salvadoran American Population") %>%
  kable_classic(full_width = F, html_font = "Cambria")  %>%
  column_spec(2:3, color = "blue") %>%
  column_spec(4,bold = T, color = "blue")
Salvadoran American Population
NAME year2019 year2010 change
California 715553 585541 130012
Texas 328905 225831 103074
Maryland 188211 120404 67807
New York 179245 141267 37978
Virginia 170670 113448 57222
Florida 75538 53158 22380
New Jersey 72631 53021 19610
Massachusetts 63516 37164 26352
North Carolina 54074 35069 19005
Georgia 45864 33875 11989
Nevada 44170 27305 16865
Arkansas 24241 12983 11258
Washington 20507 11525 8982
District of Columbia 19845 17884 1961
Illinois 19255 12903 6352
Colorado 17229 11849 5380
Arizona 15855 11428 4427
Tennessee 15266 10138 5128
Pennsylvania 14604 7119 7485
Utah 12901 7970 4931
Minnesota 12893 7631 5262
Indiana 12779 7103 5676
Ohio 10964 5306 5658
Connecticut 10364 6488 3876
Oregon 10362 6533 3829
Louisiana 8780 3870 4910
Kansas 7375 4840 2535
Iowa 7306 4993 2313
Nebraska 6667 5917 750
South Carolina 6345 3586 2759
Missouri 6294 4107 2187
Oklahoma 6268 2378 3890
Michigan 4559 2856 1703
Rhode Island 4288 3448 840
Kentucky 3843 2434 1409
New Mexico 3632 1615 2017
Alabama 3583 2038 1545
Wisconsin 2422 1612 810
Idaho 1919 869 1050
Delaware 1856 819 1037
South Dakota 1582 437 1145
Mississippi 1342 1007 335
West Virginia 1217 995 222
Alaska 1092 1062 30
New Hampshire 1043 774 269
Hawaii 786 910 -124
Maine 722 450 272
Wyoming 493 275 218
Puerto Rico 467 678 -211
Vermont 236 64 172
Montana 194 51 143
North Dakota 186 159 27

California counties

sal2019 <- get_acs(geography = "county",variables = "B03001_014",
                    state="06", year = 2019,geometry = F) %>%
             arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
sal2010 <- get_acs(geography = "county",variables = "B03001_014",
                    state="06",year = 2010,geometry = F) %>%
             arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
names(sal2019)[4] <- "year2019"
sal2019$year2010 <- sal2010$estimate
sal2019$change <- sal2019$year2019 - sal2019$year2010

sal2019[,c(2,4,6,7)] %>% arrange(desc(year2019)) %>%
  kbl(caption = "Salvadoran American Population in California") %>%
  kable_classic(full_width = F, html_font = "Cambria")  %>%
  column_spec(2:3, color = "blue") %>%
  column_spec(4,bold = T, color = "blue")
Salvadoran American Population in California
NAME year2019 year2010 change
Los Angeles County, California 425682 368626 57056
San Bernardino County, California 35290 25825 9465
Contra Costa County, California 30220 19006 11214
Orange County, California 28732 23935 4797
Riverside County, California 22850 17408 5442
San Mateo County, California 22694 18215 4479
Alameda County, California 21899 16040 5859
San Francisco County, California 15794 15432 362
Santa Clara County, California 14258 13225 1033
Fresno County, California 10507 6037 4470
Sacramento County, California 10419 6720 3699
Kern County, California 10249 9233 1016
San Diego County, California 9476 5744 3732
Ventura County, California 7436 4275 3161
Monterey County, California 6756 4261 2495
Solano County, California 6171 3748 2423
San Joaquin County, California 4898 3828 1070
Sonoma County, California 4609 2657 1952
Stanislaus County, California 4230 3069 1161
Marin County, California 3404 3413 -9
Tulare County, California 2499 1375 1124
Santa Barbara County, California 2463 1556 907
Santa Cruz County, California 1837 1017 820
Merced County, California 1599 1572 27
El Dorado County, California 1552 568 984
Placer County, California 1279 826 453
Madera County, California 1229 645 584
Yolo County, California 1204 1234 -30
Napa County, California 1099 1122 -23
Imperial County, California 939 541 398
Kings County, California 643 343 300
Butte County, California 483 610 -127
San Luis Obispo County, California 440 616 -176
Tuolumne County, California 320 60 260
Lake County, California 276 384 -108
Shasta County, California 248 281 -33
Tehama County, California 230 167 63
Humboldt County, California 228 109 119
Yuba County, California 210 133 77
San Benito County, California 155 130 25
Glenn County, California 137 76 61
Inyo County, California 120 91 29
Sutter County, California 113 230 -117
Plumas County, California 107 0 107
Nevada County, California 102 46 56
Mono County, California 93 165 -72
Colusa County, California 73 286 -213
Mendocino County, California 64 246 -182
Siskiyou County, California 49 123 -74
Amador County, California 45 70 -25
Lassen County, California 44 92 -48
Calaveras County, California 37 21 16
Modoc County, California 27 46 -19
Mariposa County, California 22 0 22
Del Norte County, California 11 10 1
Trinity County, California 2 53 -51
Alpine County, California 0 0 0
Sierra County, California 0 0 0

state Assembly Districts

sal2019 <- get_acs(geography = "state legislative district (lower chamber)",variables = "B03001_014",
                    state = "06",year = 2019) %>%
             arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
sal2010 <- get_acs(geography = "state legislative district (lower chamber)",variables = "B03001_014",
                    state="06",year = 2010,geometry = F) %>%
             arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
names(sal2019)[4] <- "year2019"
sal2019$year2010 <- sal2010$estimate
sal2019$change <- sal2019$year2019 - sal2019$year2010


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


sal2019[,c(2,4,6,7)] %>% arrange(desc(year2019)) %>%
  kbl(caption = "Salvadoran American Population \nCalifornia Assembly Districts") %>%
  kable_classic(full_width = F, html_font = "Cambria")  %>%
  column_spec(2:3, color = "blue") %>%
  column_spec(4,bold = T, color = "blue")
Salvadoran American Population California Assembly Districts
NAME year2019 year2010 change
Assembly District 59 54496 4163 50333
Assembly District 53 44963 2451 42512
Assembly District 46 43627 30551 13076
Assembly District 39 33049 38236 -5187
Assembly District 51 26349 13201 13148
Assembly District 54 23775 4330 19445
Assembly District 45 22561 37314 -14753
Assembly District 64 22140 4415 17725
Assembly District 63 21148 4709 16439
Assembly District 36 21074 17266 3808
Assembly District 62 18001 10419 7582
Assembly District 15 15753 3353 12400
Assembly District 58 15368 9810 5558
Assembly District 43 15359 13396 1963
Assembly District 14 14230 8327 5903
Assembly District 47 12468 18976 -6508
Assembly District 19 12232 10135 2097
Assembly District 18 11653 6064 5589
Assembly District 52 11436 22988 -11552
Assembly District 22 11350 3715 7635
Assembly District 48 11317 50897 -39580
Assembly District 17 11189 3569 7620
Assembly District 57 10432 10362 70
Assembly District 69 9862 7808 2054
Assembly District 38 8561 8323 238
Assembly District 31 8193 3644 4549
Assembly District 41 7968 2436 5532
Assembly District 70 7462 1959 5503
Assembly District 61 7422 10090 -2668
Assembly District 20 7159 3314 3845
Assembly District 33 6604 1613 4991
Assembly District 11 6491 9312 -2821
Assembly District 24 6426 3171 3255
Assembly District 10 6399 2076 4323
Assembly District 40 6370 25655 -19285
Assembly District 49 6242 7540 -1298
Assembly District 30 5677 4165 1512
Assembly District 66 5395 4574 821
Assembly District 32 5375 5126 249
Assembly District 60 5348 2193 3155
Assembly District 34 4935 2201 2734
Assembly District 29 4704 2482 2222
Assembly District 27 4699 2960 1739
Assembly District 68 4566 4815 -249
Assembly District 65 4498 3584 914
Assembly District 7 4481 4050 431
Assembly District 50 4444 21090 -16646
Assembly District 44 4212 9564 -5352
Assembly District 67 4192 2286 1906
Assembly District 25 4149 1739 2410
Assembly District 56 3777 7507 -3730
Assembly District 21 3765 5266 -1501
Assembly District 13 3600 7715 -4115
Assembly District 42 3158 4950 -1792
Assembly District 8 3123 3093 30
Assembly District 12 3061 11033 -7972
Assembly District 72 3036 4328 -1292
Assembly District 55 3026 7017 -3991
Assembly District 37 2913 3633 -720
Assembly District 5 2904 1982 922
Assembly District 73 2835 1233 1602
Assembly District 74 2753 825 1928
Assembly District 26 2654 3012 -358
Assembly District 4 2650 1535 1115
Assembly District 9 2618 2303 315
Assembly District 28 2500 3127 -627
Assembly District 23 2334 4715 -2381
Assembly District 6 2174 4688 -2514
Assembly District 79 2031 927 1104
Assembly District 76 1879 664 1215
Assembly District 35 1726 1299 427
Assembly District 75 1666 875 791
Assembly District 16 1537 6125 -4588
Assembly District 2 1419 1243 176
Assembly District 3 1189 885 304
Assembly District 77 1146 729 417
Assembly District 1 1095 1111 -16
Assembly District 78 1071 1001 70
Assembly District 71 1055 2420 -1365
Assembly District 80 1054 3883 -2829
sal2019[,c(2,4)]  %>% 
  top_n(n=25, year2019) %>%
  arrange(desc(year2019)) %>%
  ggplot(aes(x = year2019, y = reorder(NAME, year2019))) +
  geom_point(color = "red", size = 3) +
  labs(title = "Salvadoran American population in California",
       subtitle = "2019 American Community Survey",
       y = "",
       x = "")

State Senate Districts

sal2019 <- get_acs(geography = "state legislative district (upper chamber)",variables = "B03001_014",
                    state = "06",year = 2019) %>%
             arrange(GEOID)
## Getting data from the 2015-2019 5-year ACS
sal2010 <- get_acs(geography = "state legislative district (upper chamber)",variables = "B03001_014",
                    state="06",year = 2010,geometry = F) %>%
             arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
names(sal2019)[4] <- "year2019"
sal2019$year2010 <- sal2010$estimate
sal2019$change <- sal2019$year2019 - sal2019$year2010


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


sal2019[,c(2,4,6,7)] %>% arrange(desc(year2019)) %>%
  kbl(caption = "Salvadoran American Population \nCalifornia State Senate Districts") %>%
  kable_classic(full_width = F, html_font = "Cambria")  %>%
  column_spec(2:3, color = "blue") %>%
  column_spec(4,bold = T, color = "blue")
Salvadoran American Population California State Senate Districts
NAME year2019 year2010 change
State Senate District 30 84126 29322 54804
State Senate District 18 76012 6922 69090
State Senate District 24 73685 20485 53200
State Senate District 33 39712 4156 35556
State Senate District 35 32017 4099 27918
State Senate District 21 30524 18167 12357
State Senate District 27 28063 18462 9601
State Senate District 9 27747 13320 14427
State Senate District 20 23904 69403 -45499
State Senate District 11 23266 7780 15486
State Senate District 32 22500 19865 2635
State Senate District 22 18322 73275 -54953
State Senate District 13 17931 9255 8676
State Senate District 25 16876 30150 -13274
State Senate District 7 14962 13075 1887
State Senate District 12 13507 6544 6963
State Senate District 31 12770 9638 3132
State Senate District 34 11640 14245 -2605
State Senate District 10 11136 10022 1114
State Senate District 3 10438 13271 -2833
State Senate District 23 9549 6322 3227
State Senate District 14 9011 3262 5749
State Senate District 26 8749 64272 -55523
State Senate District 29 8541 8713 -172
State Senate District 16 7914 9345 -1431
State Senate District 28 7861 8589 -728
State Senate District 6 7602 4888 2714
State Senate District 15 7358 4294 3064
State Senate District 37 7319 8338 -1019
State Senate District 19 7204 4293 2911
State Senate District 17 6813 23947 -17134
State Senate District 2 6598 5119 1479
State Senate District 5 6592 6663 -71
State Senate District 36 4714 2596 2118
State Senate District 8 4401 20446 -16045
State Senate District 1 3953 2952 1001
State Senate District 4 3700 2181 1519
State Senate District 40 3119 3988 -869
State Senate District 39 2933 1696 1237
State Senate District 38 2484 2181 303
sal2019[,c(2,4)]  %>% 
  top_n(n=25, year2019) %>%
  arrange(desc(year2019)) %>%
  ggplot(aes(x = year2019, y = reorder(NAME, year2019))) +
  geom_point(color = "red", size = 3) +
  labs(title = "Salvadoran American population in California",
       subtitle = "2019 American Community Survey",
       y = "",
       x = "")