#Search for variables by keywords in the label
v18_Profile[grep(x = v18_Profile$label, "POVERTY"), c("name", "label")]
## # A tibble: 38 x 2
## name label
## <chr> <chr>
## 1 DP03_0119 Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME IN THE P~
## 2 DP03_0119P Percent Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME ~
## 3 DP03_0120 Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME IN THE P~
## 4 DP03_0120P Percent Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME ~
## 5 DP03_0121 Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME IN THE P~
## 6 DP03_0121P Percent Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME ~
## 7 DP03_0122 Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME IN THE P~
## 8 DP03_0122P Percent Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME ~
## 9 DP03_0123 Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME IN THE P~
## 10 DP03_0123P Percent Estimate!!PERCENTAGE OF FAMILIES AND PEOPLE WHOSE INCOME ~
## # ... with 28 more rows
v18_Profile[grep(x = v18_Profile$label, "EDUCATION"), c("name", "label")]
## # A tibble: 40 x 2
## name label
## <chr> <chr>
## 1 DP02_0058 Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over
## 2 DP02_0058P Percent Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and~
## 3 DP02_0059 Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!L~
## 4 DP02_0059P Percent Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and~
## 5 DP02_0060 Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!9~
## 6 DP02_0060P Percent Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and~
## 7 DP02_0061 Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!H~
## 8 DP02_0061P Percent Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and~
## 9 DP02_0062 Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!S~
## 10 DP02_0062P Percent Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and~
## # ... with 30 more rows
v18_Profile[grep(x = v18_Profile$label, "HEALTH INSURANCE"), c("name", "label")]
## # A tibble: 48 x 2
## name label
## <chr> <chr>
## 1 DP03_0095 Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitutionalize~
## 2 DP03_0095P Percent Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitut~
## 3 DP03_0096 Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitutionalize~
## 4 DP03_0096P Percent Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitut~
## 5 DP03_0097 Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitutionalize~
## 6 DP03_0097P Percent Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitut~
## 7 DP03_0098 Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitutionalize~
## 8 DP03_0098P Percent Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitut~
## 9 DP03_0099 Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitutionalize~
## 10 DP03_0099P Percent Estimate!!HEALTH INSURANCE COVERAGE!!Civilian noninstitut~
## # ... with 38 more rows
v18_Profile[grep(x = v18_Profile$label, "Built 2000 to 2009"), c("name", "label")]
## # A tibble: 2 x 2
## name label
## <chr> <chr>
## 1 DP04_0019 Estimate!!YEAR STRUCTURE BUILT!!Total housing units!!Built 2000 to~
## 2 DP04_0019P Percent Estimate!!YEAR STRUCTURE BUILT!!Total housing units!!Built~
sa_acs<-get_acs(geography = "tract",
state="06",
county = "059",
year = 2017,
variables=c( "DP05_0001E",
"DP03_0119PE") ,
geometry = T, output = "wide")
## Getting data from the 2013-2017 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.
#create a county FIPS code - 5 digit
sa_acs$county<-substr(sa_acs$GEOID, 1, 5)
colnames(sa_acs)[3] <- "totpop"
colnames(sa_acs)[5] <- "ppov"
library(classInt)
library(patchwork)
library(dplyr)
sa_acs2 <- sa_acs
ppov_map<-sa_acs2 %>%
mutate(cpov=cut(ppov,breaks = quantile(ppov, na.rm=T, p=seq(0,1,length.out = 6)),include.lowest = T),
jpov = cut(ppov,breaks=data.frame(classIntervals(var=sa_acs2$ppov, n=5, style="pretty")[2])[,1], include.lowest = T))
## Warning: Problem with `mutate()` input `jpov`.
## i var has missing values, omitted in finding classes
## i Input `jpov` is `cut(...)`.
## Warning in classIntervals(var = sa_acs2$ppov, n = 5, style = "pretty"): var has
## missing values, omitted in finding classes
library(ggsn)
## Loading required package: grid
library(tmap)
## Warning: replacing previous import 'sf::st_make_valid' by
## 'lwgeom::st_make_valid' when loading 'tmap'
library(tmaptools)
sa_acs2$ppov <- na.pass(sa_acs2$ppov)
tm_shape(sa_acs2)+
tm_polygons("ppov", title="% in Poverty", palette="Blues", style="quantile", n=5 ,legend.hist=T)+
tm_format("World", title="Orange County, CA Poverty Estimates - Quantile Breaks", legend.outside=T)+
tm_scale_bar()+
tm_compass()
## Warning: The shape sa_acs2 contains empty units.
tm_shape(sa_acs2)+
tm_polygons("ppov", title="% in Poverty", palette="Blues", style="jenks", n=5,legend.hist=T )+
tm_format("World", title="Orange County, CA Poverty Estimates - Jenks Breaks", legend.outside=T)+
tm_scale_bar()+
tm_compass()
## Warning: The shape sa_acs2 contains empty units.
library(mapview)
library(RColorBrewer)
pal <- colorRampPalette(brewer.pal(6, "Blues")) #set colors
mapview(ppov_map["jpov"], col.regions=pal, legend=T,map.types="OpenStreetMap", layer.name="% in Poverty")
oc_health<-get_acs(geography = "tract",
state="06",
county = "059",
year = 2018,
variables=c( "DP03_0100E",
"DP03_0101E") ,
geometry = T, output = "wide")
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile
#create a county FIPS code - 5 digit
oc_health$county<-substr(oc_health$GEOID, 1, 5)
colnames(oc_health)[3] <- "Yes_Insurance"
colnames(oc_health)[5] <- "No_insurance"
library(tmap)
library(tmaptools)
sa_acs2$ppov <- na.pass(sa_acs2$ppov)
oc_health$No_insurance <- na.pass(oc_health$No_insurance)
ggplot(oc_health, aes(fill = Yes_Insurance)) +
geom_sf()+
labs(title = "Health Insurance Coverage in Orange County, CA\nPopulation under 19 years",
subtitle="County geometry only",
caption = "Illustration by @JoeLongSanDiego ")+
theme_void()
tm_shape(oc_health)+
tm_polygons("Yes_Insurance", title="Number of persons", palette="Blues", style="quantile", n=5 ,legend.hist=T)+
tm_format("World", title="with health insurance in Orange County, CA\nunder 19 years population",
legend.outside=T)+
tm_scale_bar()+
tm_compass()
## Warning: The shape oc_health contains empty units.
tm_shape(oc_health)+
tm_polygons("No_insurance", title="Number of persons", palette="Blues", style="jenks", n=5,legend.hist=T )+
tm_format("World", title="No health insurance in Orange County, CA\nunder 19 years population ",
legend.outside=T)+
tm_scale_bar()+
tm_compass()
## Warning: The shape oc_health contains empty units.