-
Notifications
You must be signed in to change notification settings - Fork 0
/
censusdata_map
74 lines (61 loc) · 2.51 KB
/
censusdata_map
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
library(tidycensus)
library(tidyverse)
library(maps)
library(sf)
library(data.table)
data(state.fips)
library(dplyr)
library(ggplot2)
library(tmap)
library(tigris)
var_dec10 <- load_variables(2010, "sf1", cache = TRUE) #variables in decennial 2010
var_acs10 <- load_variables(2010, "acs5", cache = TRUE) #variables in acs 2010
#batch 1
#variables in batch 1
#DP02_0001 = total households acs5/profile
#B19013_001 = median household income
#B17017_002 = total households in poverty
#B22001_002 = total households with snap
#B19083_001 = tract gini inequality
#B01003_001 = total tract population
#B25097_001 = median property value
#B08006_008 = total population taking public transportation to work (except taxicab)
#B08201_002 = total households without vehicle
#B08006_017 = total population working from home
#B28002_002 = total households with internet
vt1 <- get_acs(geography = "tract",
variables = c(hh_number="DP02_0001", hh_medianincome = "B19013_001",
hh_poverty="B17017_002", hh_snap="B22002_002", #B22001_002
tract_gini="B19083_001", tract_pop="B01003_001",
hh_medianval="B25097_001", public_trans="B08006_008",
hh_novehicle="B08201_002", wfh = "B08006_017"),
state="GA", county="Fulton",
year = 2010)
vt1_dt <- as.data.table(vt1)
data_wide_vt1 <- dcast(vt1_dt, GEOID ~ variable, fun.aggregate = mean,
value.var=c("estimate"))
data_wide_vt1$pov_rate <- (data_wide_vt1$hh_poverty/data_wide_vt1$hh_number)*100
data_wide_vt1$pub_transport <- (data_wide_vt1$public_trans/data_wide_vt1$tract_pop)*100
data_wide_vt1$hh_medianincome000 <- data_wide_vt1$hh_medianincome/1000
data_wide_vt1$hh_medianval000 <- data_wide_vt1$hh_medianval/1000
data_wide_vt1$wfh <- (data_wide_vt1$wfh/data_wide_vt1$tract_pop)*100
data_wide_vt1 <- select(data_wide_vt1, GEOID, hh_medianincome000, pov_rate, hh_snap,
tract_gini, hh_medianval000, pub_transport,
hh_novehicle, wfh)
#plot
fulton_income <- get_acs(
geography = "tract",
state = "GA",
county = "Fulton",
variables = c(
med_income = "B19013_001"),
year = 2010,
geometry = TRUE)
current.mode <- tmap_mode("plot")
tmap_mode("view")
tm_shape(fulton_income) +
tm_polygons(col = "estimate",
style = "quantile",
n = 5,
palette = "Blues",
title = "Median Income\nby Census tract")