This package helps to get data from Census bureau. It includes many data including population, demographic, housing, etc. Please refer more info on this link.
There’s a list of variables names. eg. B02001_001 is the population (Estimated total by race, smallest/ granular: block group)
library(tidycensus)
#census_api_key("your api key", install = TRUE) #access the package using the api
# variable data dictionary
#thus we can see what data we want and the variable code/name of the data
#eg
v20 <- load_variables(2020, "acs5", cache = TRUE)
head(v20)
## # A tibble: 6 × 4
## name label concept geography
## <chr> <chr> <chr> <chr>
## 1 B01001_001 Estimate!!Total: SEX BY AGE block group
## 2 B01001_002 Estimate!!Total:!!Male: SEX BY AGE block group
## 3 B01001_003 Estimate!!Total:!!Male:!!Under 5 years SEX BY AGE block group
## 4 B01001_004 Estimate!!Total:!!Male:!!5 to 9 years SEX BY AGE block group
## 5 B01001_005 Estimate!!Total:!!Male:!!10 to 14 years SEX BY AGE block group
## 6 B01001_006 Estimate!!Total:!!Male:!!15 to 17 years SEX BY AGE block group
County the 9 neighborhoods in:
| Neighborhood | County | City, States |
|---|---|---|
| New East Side | Franklin | Columbus, OH |
| Avondale | Hamilton | Cincinnati, OH |
| Buckeye | Cuyahoga | Cleveland, OH |
| Arlington woods | Marion | Indianapolis, IN |
| Russell | Jefferson | Louisville, KY |
| South Chicago | Cook | Chicago, IL |
| Groove Park | Fulton | Atlanta, GA |
| Historic West end | Mecklenburg | Charlotte, NC |
| East Tampa | Hillsborough | Tampa, FL |
Now we get data of 9 neighborhoods from census bureau.
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.4 ✓ stringr 1.4.0
## ✓ readr 2.0.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
Multi_Dem_2020 <- get_acs(geography = "tract", year=2020,
state = c("OH","IL","FL","GA","IN","KY","NC"),
geometry = TRUE,
variables = c(population = "B02001_001",
median.gross.rent = "B25064_001",
median.household.income = "B19013_001",
rent.burden = "B25071_001",
white = "B03002_003",
af.am = "B03002_004",
hispanic = "B03002_012",
am.ind_native = "B03002_005",
asian = "B03002_006",
nh.pi = "B03002_007",
multiple = "B03002_009",
other = "B03002_008"),
output = 'wide')%>%
mutate(census_tract=sub("\\,.*", "", NAME))# extract census tract number
## Getting data from the 2016-2020 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Fetching tract data by state and combining the result.
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|========= | 12%
|
|========= | 13%
|
|================== | 26%
|
|=================== | 28%
|
|=============================== | 44%
|
|================================== | 48%
|
|================================== | 49%
|
|======================================= | 55%
|
|========================================= | 58%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 65%
|
|=============================================== | 67%
|
|================================================= | 70%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|===================================================== | 76%
|
|======================================================= | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|============================================================= | 87%
|
|================================================================ | 91%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|=================================================================== | 96%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 2%
|
|== | 3%
|
|================================ | 46%
|
|================================== | 48%
|
|===================================== | 52%
|
|======================================================================| 100%
##
|
| | 0%
|
| | 1%
|
|== | 3%
|
|=== | 4%
|
|============================================ | 64%
|
|============================================================== | 88%
|
|======================================================================| 100%
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|== | 3%
|
|=== | 4%
|
|==== | 6%
|
|======= | 11%
|
|======== | 11%
|
|================== | 25%
|
|==================================== | 52%
|
|===================================== | 52%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|============================================ | 63%
|
|================================================= | 70%
|
|================================================== | 71%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 79%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 2%
|
|===== | 7%
|
|======= | 10%
|
|================ | 23%
|
|=================== | 28%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|=== | 5%
|
|==== | 6%
|
|======= | 10%
|
|=============== | 22%
|
|================================================================ | 91%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|===================================================================== | 99%
|
|======================================================================| 100%
##
|
| | 0%
|
| | 1%
|
|=== | 4%
|
|=== | 5%
|
|==== | 6%
|
|===== | 7%
|
|======= | 10%
|
|========= | 13%
|
|========== | 15%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|==================== | 29%
|
|======================= | 33%
|
|========================= | 35%
|
|============================== | 43%
|
|=================================== | 50%
|
|===================================================== | 76%
|
|======================================================= | 79%
|
|======================================================================| 100%
#extract census tract
# neighbor_demon<- Multi_Dem_2020%>%
# filter(GEOID%in%df_tract$Tract.number)%>%
# mutate(Name = str_remove(NAME, "Census Tract"))%>%
# mutate(census_tact=sub("\\,.*", "", Name))
Map 9 neighborhoods with their census tract number label.
df_tract<- read.csv("/Users/teresa/Downloads/tract list.csv")
Multi_Dem_2020<-Multi_Dem_2020%>%
mutate(census_num = str_remove(census_tract, "Census Tract"))
#avondale
avondale_list<- df_tract%>%
filter(Neighborhood=="Avondale")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%avondale_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("Avondale --2020 population")
#grove park
# c("13121008400", "13121008301","13121008500")
grove_park_list<- df_tract%>%
filter(Neighborhood=="Grove Park")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%grove_park_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("Grove park --2020 population")
#south chicago--------------------------
south_chicago_list<- df_tract%>%
filter(Neighborhood=="South Chicago")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%south_chicago_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("South Chicago --2020 population")
#East Tampa-----------------------------
East_Tampa_list<- df_tract%>%
filter(Neighborhood=="East Tampa")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%East_Tampa_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("East Tampa --2020 population")
#Arlington Woods
Arlington_Woods_list<- df_tract%>%
filter(Neighborhood=="Arlington Woods")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%Arlington_Woods_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("Arlington Woods --2020 population")
#Russell
Russell_list<- df_tract%>%
filter(Neighborhood=="Russell")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%Russell_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("Russell --2020 population")
#Historic West End
Historic_West_End_list<- df_tract%>%
filter(Neighborhood=="Historic West End")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%Historic_West_End_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("Historic West End --2020 population")
#Buckeye
Buckeye_list<- df_tract%>%
filter(Neighborhood=="Buckeye")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%Buckeye_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("Buckeye --2020 population")
#Near East Side
Near_East_Side_list<- df_tract%>%
filter(Neighborhood=="Near East Side")%>%
select(Tract.number)
Multi_Dem_2020%>%
filter(GEOID%in%Near_East_Side_list$Tract.number)%>%
ggplot()+
geom_sf(mapping=aes(fill=populationE))+
geom_sf_label(aes(label = census_num))+
ggtitle("Near East Side --2020 population")
Get data of 9 neighborhoods from year 2017-2020, summarize and compare their population and median households income changes.
multi_state_2020 <- get_acs(
state = c("OH","IN","IL","KY","NC","GA","FL"),
geography = "tract",
variables = c(population="B02001_001",
med.house.income="B19013_001",
rent.burden="B25071_001"),
geometry = TRUE,
year = 2020,
output='wide'
)
## Getting data from the 2016-2020 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Fetching tract data by state and combining the result.
multi_state_2019 <- get_acs(
state = c("OH","IN","IL","KY","NC","GA","FL"),
geography = "tract",
variables = c(population="B02001_001",
med.house.income="B19013_001",
rent.burden="B25071_001"),
geometry = TRUE,
year = 2019,
output='wide'
)
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Fetching tract data by state and combining the result.
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|======= | 10%
|
|======== | 11%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|=========== | 16%
|
|============ | 18%
|
|============== | 21%
|
|=============== | 22%
|
|================ | 23%
|
|================= | 24%
|
|================== | 25%
|
|=================== | 27%
|
|==================== | 29%
|
|===================== | 30%
|
|======================= | 33%
|
|======================== | 34%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|============================ | 40%
|
|============================== | 42%
|
|=============================== | 44%
|
|================================ | 45%
|
|================================= | 47%
|
|================================== | 49%
|
|=================================== | 50%
|
|===================================== | 53%
|
|=========================================== | 61%
|
|============================================= | 65%
|
|=============================================== | 68%
|
|================================================= | 70%
|
|=================================================== | 73%
|
|======================================================= | 78%
|
|======================================================== | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|=========================================================== | 84%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 93%
|
|=================================================================== | 96%
|
|======================================================================| 100%
##
|
| | 0%
|
|== | 2%
|
|===== | 6%
|
|====== | 9%
|
|=========== | 15%
|
|============ | 17%
|
|======================================================================| 100%
##
|
| | 0%
|
|== | 2%
|
|===== | 7%
|
|====== | 8%
|
|=========== | 16%
|
|============= | 19%
|
|======================================== | 57%
|
|============================================================== | 88%
|
|================================================================ | 92%
|
|================================================================= | 93%
|
|======================================================================| 100%
##
|
| | 0%
|
|====== | 8%
|
|================================================================= | 92%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|==== | 6%
|
|======================================= | 56%
|
|======================================== | 57%
|
|========================================= | 58%
|
|========================================== | 60%
|
|=========================================== | 62%
|
|========================================================= | 82%
|
|============================================================ | 85%
|
|======================================================================| 100%
##
|
| | 0%
|
|==== | 6%
|
|========= | 13%
|
|======================== | 35%
|
|========================== | 37%
|
|============================================================= | 87%
|
|============================================================== | 88%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|== | 3%
|
|=== | 4%
|
|========== | 14%
|
|============= | 18%
|
|================================= | 46%
|
|================================= | 47%
|
|=================================== | 50%
|
|==================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|======================================== | 58%
|
|========================================= | 59%
|
|================================================= | 70%
|
|=================================================== | 73%
|
|======================================================================| 100%
multi_state_2018 <- get_acs(
state = c("OH","IN","IL","KY","NC","GA","FL"),
geography = "tract",
variables = c(population="B02001_001",
med.house.income="B19013_001",
rent.burden="B25071_001"),
geometry = TRUE,
year = 2018,
output='wide'
)
## Getting data from the 2014-2018 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Fetching tract data by state and combining the result.
##
|
| | 0%
|
|=== | 4%
|
|=== | 5%
|
|===== | 7%
|
|========= | 12%
|
|======================================================================| 100%
##
|
| | 0%
|
|== | 2%
|
|=== | 4%
|
|====== | 9%
|
|========= | 13%
|
|============ | 17%
|
|======================= | 33%
|
|============================= | 42%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|==== | 6%
|
|====== | 8%
|
|======== | 12%
|
|================================= | 47%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|=== | 5%
|
|==== | 6%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 16%
|
|======================================================================| 100%
##
|
| | 0%
|
|== | 2%
|
|== | 3%
|
|=== | 5%
|
|==== | 6%
|
|======================================================= | 78%
|
|=========================================================== | 84%
|
|============================================================= | 87%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|==== | 6%
|
|======== | 12%
|
|================================================================== | 94%
|
|======================================================================| 100%
##
|
| | 0%
|
|=== | 4%
|
|==== | 5%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================== | 88%
|
|=============================================================== | 90%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|======================================================================| 100%
multi_state_2017 <- get_acs(
state = c("OH","IN","IL","KY","NC","GA","FL"),
geography = "tract",
variables = c(population="B02001_001",
med.house.income="B19013_001",
rent.burden="B25071_001"),
geometry = TRUE,
year = 2017,
output='wide'
)
## 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)`.
## Fetching tract data by state and combining the result.
##
|
| | 0%
|
|= | 1%
|
|=== | 5%
|
|===== | 7%
|
|======= | 10%
|
|============ | 17%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|===================================================================== | 98%
|
|======================================================================| 100%
##
|
| | 0%
|
|== | 2%
|
|===== | 7%
|
|====== | 9%
|
|======== | 11%
|
|========= | 13%
|
|=============== | 22%
|
|====================== | 31%
|
|============================================= | 64%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|============================================================ | 86%
|
|======================================================================| 100%
##
|
| | 0%
|
|=== | 5%
|
|====== | 8%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|== | 3%
|
|======================================================= | 79%
|
|=================================================================== | 96%
|
|======================================================================| 100%
##
|
| | 0%
|
|= | 1%
|
|==== | 5%
|
|===== | 7%
|
|============================================================== | 89%
|
|================================================================ | 91%
|
|================================================================= | 93%
|
|=================================================================== | 96%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
##
|
| | 0%
|
|====== | 8%
|
|====== | 9%
|
|=========== | 16%
|
|===================== | 30%
|
|===================== | 31%
|
|======================== | 34%
|
|========================= | 35%
|
|============================================================ | 86%
|
|==================================================================== | 97%
|
|===================================================================== | 98%
|
|======================================================================| 100%
library(tidyverse)
df_census<- read.csv("/Users/teresa/Desktop/census tract.csv")[,1:2]
census_2020<- multi_state_2020%>%filter(GEOID%in%df_census$Census_tract)
census_2019<- multi_state_2019%>%filter(GEOID%in%df_census$Census_tract)
census_2018<- multi_state_2018%>%filter(GEOID%in%df_census$Census_tract)
census_2017<- multi_state_2017%>%filter(GEOID%in%df_census$Census_tract)
census_2020_test<- multi_state_2020%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(med_avg=mean(med.house.incomeE))
census_2019_test<- multi_state_2019%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(med_avg=mean(med.house.incomeE))
census_2018_test<- multi_state_2018%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(med_avg=mean(med.house.incomeE))
census_2017_test<- multi_state_2017%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(med_avg=mean(med.house.incomeE))
#population
census_2020_pop<- multi_state_2020%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(pop_sum=sum(populationE))
census_2019_pop<- multi_state_2019%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(pop_sum=sum(populationE))
census_2018_pop<- multi_state_2018%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(pop_sum=sum(populationE))
census_2017_pop<- multi_state_2017%>%filter(GEOID%in%df_census$Census_tract)%>%
separate(col=NAME, sep=",", into = c("census_num", "county","states"))%>%
group_by(county)%>%
summarize(pop_sum=sum(populationE))
#library(tidycensus)
library(ggiraph)
#library(tidyverse)
library(patchwork)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
oh_income <- get_acs(
geography = "county",
variables = "B19013_001",
state = "OH",
year = 2020,
geometry = TRUE
) %>%
mutate(NAME = str_remove(NAME, " County, Ohio"))
## Getting data from the 2016-2020 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%
|
|===== | 7%
|
|====== | 8%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|============= | 18%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 29%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|==================================== | 51%
|
|===================================== | 53%
|
|====================================== | 54%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|=================================================== | 74%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|===================================================================== | 99%
|
|======================================================================| 100%
#interactive maps
vt_map <- ggplot(oh_income, aes(fill = estimate)) +
geom_sf_interactive(aes(data_id = GEOID)) +
scale_fill_distiller(palette = "Greens",
direction = 1,
guide = "none") +
theme_void()
vt_plot <- ggplot(oh_income, aes(x = estimate, y = reorder(NAME, estimate),
fill = estimate)) +
geom_errorbar(aes(xmin = estimate - moe, xmax = estimate + moe)) +
geom_point_interactive(color = "black", size = 4, shape = 21,
aes(data_id = GEOID)) +
scale_fill_distiller(palette = "Greens", direction = 1,
labels = label_dollar()) +
scale_x_continuous(labels = label_dollar()) +
labs(title = "Household income by county in Ohio",
subtitle = "2016-2020 American Community Survey",
y = "",
x = "ACS estimate (bars represent margin of error)",
fill = "ACS estimate") +
theme_minimal(base_size = 14)
girafe(ggobj = vt_map + vt_plot, width_svg = 10, height_svg = 5) %>%
girafe_options(opts_hover(css = "fill:cyan;"))
To search for the MSA number. link
Map of Moved in vs Moved out of Cincinnati
library(sf)
## Linking to GEOS 3.9.1, GDAL 3.4.0, PROJ 8.1.1; sf_use_s2() is TRUE
hamilton_flows <- get_flows(
geography = "metropolitan statistical area",
msa = 17140,
year = 2018,
geometry = TRUE
)
hamilton_flows %>%
head()
## Simple feature collection with 6 features and 7 fields
## Active geometry column: centroid1
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -84.46462 ymin: 39.0811 xmax: -84.46462 ymax: 39.0811
## Geodetic CRS: NAD83
## # A tibble: 6 × 9
## GEOID1 GEOID2 FULL1_NAME FULL2_NAME variable estimate moe
## <chr> <chr> <chr> <chr> <chr> <dbl> <dbl>
## 1 17140 <NA> Cincinnati, OH-KY… Outside Metro Area w… MOVEDIN 14192 1364
## 2 17140 <NA> Cincinnati, OH-KY… Outside Metro Area w… MOVEDOUT 14012 1039
## 3 17140 <NA> Cincinnati, OH-KY… Outside Metro Area w… MOVEDNET 180 1586
## 4 17140 <NA> Cincinnati, OH-KY… Africa MOVEDIN 573 200
## 5 17140 <NA> Cincinnati, OH-KY… Africa MOVEDOUT NA NA
## 6 17140 <NA> Cincinnati, OH-KY… Africa MOVEDNET NA NA
## # … with 2 more variables: centroid1 <POINT [°]>, centroid2 <POINT [°]>
library(mapdeck)
#need mapbox api token to use mapdeck map
set_token('pk.eyJ1IjoidGVyZXNhMjAyMiIsImEiOiJjbDV5b2h6cnYxNXI4M2psM3VicGhha2Z4In0.VOXaZT2sE-JOQOvK8vC5yg')
mapdeck_tokens()
## Mapdeck tokens
## - mapbox : pk.eyJ1IjoidGVyZXNhMjAyMiIsImEiOiJjbDV5b2h6cnYxNXI4M2psM3VicGhha2Z4In0.VOXaZT2sE-JOQOvK8vC5yg
#moved in
top_move_in <- hamilton_flows %>%
filter(!is.na(GEOID2), variable == "MOVEDIN") %>%
slice_max(n = 25, order_by = estimate) %>%
mutate(
width = estimate / 500,
tooltip = paste0(
scales::comma(estimate * 5, 1),
" people moved from ", str_remove(FULL2_NAME, "Metro Area"),
" to ", str_remove(FULL1_NAME, "Metro Area"), " between 2014 and 2018"
)
)
top_move_in %>%
mapdeck(style = mapdeck_style("dark"), pitch = 45) %>%
add_arc(
origin = "centroid1",
destination = "centroid2",
stroke_width = "width",
auto_highlight = TRUE,
highlight_colour = "#8c43facc",
tooltip = "tooltip"
)
# moved out
top_move_out <- hamilton_flows %>%
filter(!is.na(GEOID2), variable == "MOVEDOUT") %>%
slice_max(n = 25, order_by = estimate) %>%
mutate(
width = estimate / 500,
tooltip = paste0(
scales::comma(estimate * 5, 1),
" people moved from ", str_remove(FULL1_NAME, "Metro Area"),
" to ", str_remove(FULL2_NAME, "Metro Area"), " between 2014 and 2018"
)
)
top_move_out %>%
mapdeck(style = mapdeck_style("dark"), pitch = 45) %>%
add_arc(
origin = "centroid1",
destination = "centroid2",
stroke_width = "width",
auto_highlight = TRUE,
highlight_colour = "#FFFFA9FF",
tooltip = "tooltip"
)
Map of advondale block group and color by the population density.
#Avondale population block group
avondale_block_data <- get_acs(geography = "block group",
year=2020,
state = "OH",
geometry = TRUE,
variables = c(population = "B02001_001",
median.gross.rent = "B25064_001",
median.household.income = "B19013_001",
rent.burden = "B25071_001",
white = "B03002_003",
af.am = "B03002_004",
hispanic = "B03002_012",
am.ind_native = "B03002_005",
asian = "B03002_006",
nh.pi = "B03002_007",
multiple = "B03002_009",
other = "B03002_008"),
output = 'wide')%>%
filter(grepl("^39061006800|^39061006900|^39061006600|^39061027000",GEOID))
## Getting data from the 2016-2020 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%
|
|= | 2%
|
|== | 3%
|
|===== | 7%
|
|======== | 12%
|
|========= | 13%
|
|=========================== | 38%
|
|=============================== | 44%
|
|================================== | 48%
|
|================================== | 49%
|
|======================================= | 56%
|
|============================================== | 66%
|
|======================================================== | 80%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|============================================================== | 89%
|
|======================================================================| 100%
OHDem_2020 <- get_acs(geography = "tract", year=2020,
state = "OH", geometry = TRUE,
variables = c(population = "B02001_001",
median.gross.rent = "B25064_001",
median.household.income = "B19013_001",
rent.burden = "B25071_001",
white = "B03002_003",
af.am = "B03002_004",
hispanic = "B03002_012",
am.ind_native = "B03002_005",
asian = "B03002_006",
nh.pi = "B03002_007",
multiple = "B03002_009",
other = "B03002_008"),
output = 'wide')
## Getting data from the 2016-2020 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
OHDem_hamilton_2020 <- get_acs(geography = "tract", year=2020,
state = "OH", county = "hamilton", geometry = TRUE,
variables = c(population = "B02001_001",
median.gross.rent = "B25064_001",
median.household.income = "B19013_001",
rent.burden = "B25071_001",
white = "B03002_003",
af.am = "B03002_004",
hispanic = "B03002_012",
am.ind_native = "B03002_005",
asian = "B03002_006",
nh.pi = "B03002_007",
multiple = "B03002_009",
other = "B03002_008"),
output = 'wide')
## Getting data from the 2016-2020 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
OHPct_2020<-OHDem_2020%>%
mutate(checkTotE = whiteE +af.amE+hispanicE+am.ind_nativeE+ # looks good!
asianE+nh.piE+multipleE+otherE)%>%
mutate(pct.whiteE = whiteE/checkTotE,
pct.af.amE = af.amE/checkTotE,
pct.hispanicE = hispanicE/checkTotE,
pct.am.ind_nativeE = am.ind_nativeE/checkTotE,
pct.asianE = asianE/checkTotE,
pct.nh.piE = nh.piE/checkTotE,
pct.multipleE = multipleE/checkTotE,
pct.otherE = otherE/checkTotE,
year = 2020)
OHPct_hamilton_2020<-OHDem_hamilton_2020%>%
mutate(checkTotE = whiteE +af.amE+hispanicE+am.ind_nativeE+ # looks good!
asianE+nh.piE+multipleE+otherE)%>%
mutate(pct.whiteE = whiteE/checkTotE,
pct.af.amE = af.amE/checkTotE,
pct.hispanicE = hispanicE/checkTotE,
pct.am.in_natived_nativeE = am.ind_nativeE/checkTotE,
pct.asianE = asianE/checkTotE,
pct.nh.piE = nh.piE/checkTotE,
pct.multipleE = multipleE/checkTotE,
pct.otherE = otherE/checkTotE,
year = 2020)
Avondale_2020<- OHPct_2020%>%
filter(GEOID%in%c("39061006800","39061006900","39061006600","39061027000"))
plot(Avondale_2020["populationE"])
avondale_block_map<- ggplot()+
geom_sf(data=Avondale_2020,mapping=aes(fill=populationE))+
ggtitle("Avondale --2020 population")
avondale_block_map