DP02PR_0069 Estimate!!VETERAN STATUS!!Civilian population 18 years and over

DP02_0069P Percent Estimate!!VETERAN STATUS!!Civilian population 18 years and over

#Search for variables by keywords in the label

v10_Profile <- load_variables(2010 , "acs5/profile", cache = TRUE) #demographic profile tables
v18_Profile <- load_variables(2018 , "acs5/profile", cache = TRUE) #demographic profile tables

v10_Profile[grep(x = v10_Profile$label, "VETERAN"), c("name", "label")]
## # A tibble: 8 x 2
##   name         label                                                          
##   <chr>        <chr>                                                          
## 1 DP02_0068    Estimate!!VETERAN STATUS!!Civilian population 18 years and over
## 2 DP02_0068P   Percent!!VETERAN STATUS!!Civilian population 18 years and over 
## 3 DP02_0069    Estimate!!VETERAN STATUS!!Civilian veterans                    
## 4 DP02_0069P   Percent!!VETERAN STATUS!!Civilian veterans                     
## 5 DP02PR_0068  Estimate!!VETERAN STATUS!!Civilian population 18 years and over
## 6 DP02PR_0068P Percent!!VETERAN STATUS!!Civilian population 18 years and over 
## 7 DP02PR_0069  Estimate!!VETERAN STATUS!!Civilian veterans                    
## 8 DP02PR_0069P Percent!!VETERAN STATUS!!Civilian veterans
v18_Profile[grep(x = v18_Profile$label, "VETERAN"), c("name", "label")]
## # A tibble: 8 x 2
##   name        label                                                             
##   <chr>       <chr>                                                             
## 1 DP02_0068   Estimate!!VETERAN STATUS!!Civilian population 18 years and over   
## 2 DP02_0068P  Percent Estimate!!VETERAN STATUS!!Civilian population 18 years an~
## 3 DP02_0069   Estimate!!VETERAN STATUS!!Civilian population 18 years and over!!~
## 4 DP02_0069P  Percent Estimate!!VETERAN STATUS!!Civilian population 18 years an~
## 5 DP02PR_0068 Estimate!!VETERAN STATUS!!Civilian population 18 years and over   
## 6 DP02PR_006~ Percent Estimate!!VETERAN STATUS!!Civilian population 18 years an~
## 7 DP02PR_0069 Estimate!!VETERAN STATUS!!Civilian population 18 years and over!!~
## 8 DP02PR_006~ Percent Estimate!!VETERAN STATUS!!Civilian population 18 years an~
v18_Profile[grep(x = v18_Profile$label, "DISABILITY"), c("name", "label")]
## # A tibble: 32 x 2
##    name       label                                                             
##    <chr>      <chr>                                                             
##  1 DP02_0070  Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIONALIZED ~
##  2 DP02_0070P Percent Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIO~
##  3 DP02_0071  Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIONALIZED ~
##  4 DP02_0071P Percent Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIO~
##  5 DP02_0072  Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIONALIZED ~
##  6 DP02_0072P Percent Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIO~
##  7 DP02_0073  Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIONALIZED ~
##  8 DP02_0073P Percent Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIO~
##  9 DP02_0074  Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIONALIZED ~
## 10 DP02_0074P Percent Estimate!!DISABILITY STATUS OF THE CIVILIAN NONINSTITUTIO~
## # ... with 22 more rows
us_vet<-get_acs(geography = "county",
                year = 2018,
                variables=c("DP02_0069P" ,"DP02_0069"),
                geometry = F, output = "wide") %>% arrange(GEOID)
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile
## Warning: `funs()` is deprecated as of dplyr 0.8.0.
## Please use a list of either functions or lambdas: 
## 
##   # Simple named list: 
##   list(mean = mean, median = median)
## 
##   # Auto named with `tibble::lst()`: 
##   tibble::lst(mean, median)
## 
##   # Using lambdas
##   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
top_n(us_vet,n=20,DP02_0069E) %>%
 
  ggplot(aes(x = DP02_0069E, y = reorder(NAME, DP02_0069E))) +
  geom_point(color = "brown4", size = 3) +
  labs(title = "Veteran population _ top 20 counties",
       subtitle = "2019 Census American Community Survey",
       y = "",
       x = "Population estimate")  

top_n(us_vet,n=20,DP02_0069PE) %>%
 
  ggplot(aes(x = DP02_0069PE, y = reorder(NAME, DP02_0069PE))) +
  geom_point(color = "brown4", size = 3) +
  labs(title = "Percent Veteran population _ top 20 counties",
       subtitle = "2019 Census American Community Survey",
       y = "",
       x = "Percent Population estimate")  

2018 California

ca_vet<-get_acs(geography = "county",
                state="06",
                
                year = 2018,
                variables=c("DP02_0069P" ,"DP02_0069"),
                geometry = F, output = "wide") %>% arrange(GEOID)
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile
top_n(ca_vet,n=20,DP02_0069E) %>%
  mutate(NAME = gsub(" County, California", "", NAME)) %>%
  ggplot(aes(x = DP02_0069E, y = reorder(NAME, DP02_0069E))) +
  geom_point(color = "brown4", size = 3) +
  labs(title = "Veteran population _ top 20 counties in California",
       subtitle = "2018 Census American Community Survey",
       y = "",
       x = "Population estimate")  

us_vet<-get_acs(geography = "county",
                year = 2018,
                variables=c("DP02_0069P" ,"DP02_0069"),
                geometry = F, output = "wide") %>% arrange(GEOID)
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile

2010 California DP02_0069

vet_2018<-get_acs(geography = "county",
                state="06",
                year = 2018,
                variables=c("DP02_0069P" ,"DP02_0069"),
                geometry = F, output = "wide") %>% arrange(GEOID)
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile
vet_2010<-get_acs(geography = "county",
                state="06",
                year = 2010,
                variables=c("DP02_0069P" ,"DP02_0069"),
                geometry = F, output = "wide") %>% arrange(GEOID)
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
vet_2018$P2010 <- vet_2010$DP02_0069E
vet_2018$change <- vet_2018$DP02_0069E - vet_2010$DP02_0069E



top_n(vet_2018,n=-20,change) %>%
  mutate(NAME = gsub(" County, California", "", NAME)) %>%
  ggplot(aes(x = DP02_0069E, y = reorder(NAME, DP02_0069E))) +
  geom_point(color = "red", size = 3) +
  labs(title = "Declines in Veteran population _ top 20 counties in California",
       subtitle = "Census variable # DP02_0069\nFrom 2010 to 2018 ", caption = "Illustration by Joe Long",
       y = "",
       x = "Population declines")  

change <- select(vet_2018,c(2,8))

top_n(change,n=-20,change) %>% arrange(change)%>% kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>%
   column_spec(2, T, color = "blue" ) 
NAME change
Los Angeles County, California -97666
Orange County, California -32772
San Diego County, California -24520
San Bernardino County, California -23872
Santa Clara County, California -21252
Sacramento County, California -21054
Alameda County, California -19879
Riverside County, California -19308
Contra Costa County, California -15312
San Mateo County, California -11020
Kern County, California -10510
Ventura County, California -10292
San Francisco County, California -9040
Fresno County, California -9021
San Joaquin County, California -7887
Sonoma County, California -6825
San Luis Obispo County, California -6187
Butte County, California -6073
Santa Barbara County, California -6058
Stanislaus County, California -5853
top_n(change,n=-10,change) %>% arrange(change) %>% 
  ggplot(aes(x=reorder(NAME,change),y=change,fill=NAME)) + 
   geom_bar(stat = "identity") +
  labs(title = "Declines _ Veteran Population by top ten CA counties ", 
      subtitle = "From 2010 to 2018 Census Survey Variable# DP02_0069",
       x="County", y="count",
       caption = "Data source: Census data ACS\nIllustration by @JoeLongSanDiego")+
  theme(legend.position = "none")+
  coord_flip()

library(tmap)
## Warning: replacing previous import 'sf::st_make_valid' by
## 'lwgeom::st_make_valid' when loading 'tmap'
library(tmaptools)

ca_vet<-get_acs(geography = "county",
                state="06",
                
                year = 2018,
                variables=c("DP02_0069P" ,"DP02_0069"),
                geometry = T, output = "wide") %>% arrange(GEOID)
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile
tm_shape(ca_vet)+
  tm_polygons("DP02_0069E", title="Number of persons", palette="Blues", style="quantile", n=10 ,legend.hist=T)+
  tm_format("World", title="Veteran Population in California Counties", legend.outside=T)+
  tm_scale_bar()+
  tm_compass()

tm_shape(ca_vet)+
  tm_polygons("DP02_0069PE", title="% in county population", palette="Blues", style="jenks", n=5,legend.hist=T )+
  tm_format("World", title="Percentage _ Veteran Population in California Counties", legend.outside=T)+
  tm_scale_bar()+
  tm_compass()

Orange county

oc_vet<-get_acs(geography = "tract",
                state="06",
                county = "059",
                year = 2018,
                variables=c("DP02_0069P" ,"DP02_0069"),
                geometry = T, output = "wide") %>% arrange(GEOID)
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile
oc_vet$DP02_0069E <- na.omit(oc_vet$DP02_0069E) 

tm_shape(oc_vet)+
  tm_polygons("DP02_0069E", title="Population estimate", palette="Blues", style="quantile", n=5 ,legend.hist=T)+
  tm_format("World", title="Veteran Population by Census tracts in Orange county, CA", legend.outside=T)+
  tm_scale_bar()+
  tm_compass()
## Warning: The shape oc_vet contains empty units.

tm_shape(oc_vet)+
  tm_polygons("DP02_0069PE", title="Population estimate", palette="Blues", style="quantile", n=8 ,legend.hist=T)+
  tm_format("World", title="Percentage Population_ Veteran Population by Census tracts in Orange county, CA", legend.outside=T)+
  tm_scale_bar()+
  tm_compass()
## Warning: The shape oc_vet contains empty units.

library(mapview)
library(RColorBrewer)
pal <- colorRampPalette(brewer.pal(6, "Blues")) #set colors


mapview(oc_vet["DP02_0069E"], col.regions=pal, legend=T,map.types="OpenStreetMap", 
        layer.name="% Veteran in Census tract population")