-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcensus-lesson.qmd
141 lines (116 loc) · 2.63 KB
/
census-lesson.qmd
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
title: "census lesson"
format: html
---
## modified for check
```{r}
library(tidycensus)
library(dplyr)
library(tidyr)
library(ggplot2)
```
```{r}
census_api_key("0b213304aba6e6f5f5b4a5ed66e13ccc2478dfc4", install = TRUE)
```
# Decennial population by State
```{r}
pop_2020 <- get_decennial(
geography = "state",
variable = "P1_001N",
year = 2020)
```
```{r}
pop_2010 <- get_decennial(
geography = "state",
variables = "P001001",
year = 2010)
```
```{r}
table_p2_2020 <- get_decennial(
geography = "state",
table = "P2",
year = 2020)
```
```{r}
unique(table_p2_2020$variable)
```
```{r}
vars_pl_2020 <- load_variables(2020, "pl")
## for 20210
vars_pl_2010 <- load_variables(2010, "pl")
```
```{r}
vars_dhc_2020 <- load_variables(2020, "dhc")
## Note you have to specify the file with sumfile =
household_2020 <- get_decennial(
geography = "state",
variable = "H10_001N",
year = 2020,
sumfile = "dhc")
```
```{r}
delta_hispanic <- get_decennial(
geography = "county",
state = "CA",
county = c("Alameda", "Contra Costa", "Sacramento", "San Joaquin", "Solano", "Yolo"),
variables = "P2_002N",
year = 2020)
```
```{r}
## Vector with race variables codes
race_vars <- c(
Hispanic = "P2_002N",
White = "P2_005N",
Black = "P2_006N",
Native = "P2_007N",
Asian = "P2_008N",
HIPI = "P2_009N") ## Native Hawaiian and other Pacific Islander
delta_race <- get_decennial(
geography = "county",
state = "CA",
county = c("Alameda", "Contra Costa", "Sacramento", "San Joaquin", "Solano", "Yolo"),
variables = race_vars,
summary_var = "P2_001N",
year = 2020)
```
```{r}
delta_track_hw <- get_decennial(
geography = "tract",
variables = c(hispanic = "P2_002N",
white = "P2_005N"),
summary_var = "P2_001N",
state = "CA",
county = c("Alameda", "Contra Costa", "Sacramento", "San Joaquin", "Solano", "Yolo"),
year = 2020)
```
```{r}
delta_track_clean <- delta_track_hw %>%
mutate(percent = 100 * (value / summary_value)) %>%
separate(NAME, into = c("tract", "county", "state"),
sep = ", ")
```
```{r}
ggplot(delta_track_clean,
aes(x = percent, fill = county)) +
geom_density(alpha = 0.3)+
facet_wrap(~variable)+
theme_light()
```
```{r}
## 1-year survey
median_income_1yr <- get_acs(
geography = "county",
variables = "B19013_001",
state = "CA",
year = 2021,
survey = "acs1")
## 5-year survey. Defaults to the 2017-2021 5-year ACS
median_income_5yr <- get_acs(
geography = "county",
variables = "B19013_001",
state = "CA")
```
```{r}
## variables for 5-year 2017-2021 ACS
vars <- load_variables(2021, "acs5")
```