generated from KSUDS/p2_data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
analysis.R
83 lines (57 loc) · 1.68 KB
/
analysis.R
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
library(tidyverse)
library(ggplot2)
library(waffle)
library(dplyr)
httpgd::hgd()
httpgd::hgd_browse()
dat <- read_csv("full_data.csv") %>%
select(-...1)
dat
dat_pop <- tibble(
race = c("Asian/Pacific Islander",
"Black", "Hispanic",
"Native American/Native Alaskan", "White"),
N = 331449281 * c(.061, .134, .185, .013, .763))
dat_pop
dat <- dat %>%
group_by(race, year) %>%
summarise(n = n()) %>%
ungroup()
dat_merge <- merge(dat, dat_pop)
glimpse(dat_merge)
glimpse(dat)
datrace <- dat %>% group_by(race, education)
dat_merge %>%
ggplot(aes(x = race, y = year, fill = n / N)) +
geom_tile() +
geom_fit_text(aes(label = n / N), color = "white", size = 4, contrast = TRUE) +
scale_fill_viridis_c() +
coord_fixed()
datrace
testdata <- read_csv("full_data.csv")
glimpse(testdata)
dat_plot <- testdata %>%
group_by(race, education) %>%
summarise(n = n()) %>%
ungroup()
glimpse(dat_plot)
dat_testsum <- testdata %>%
group_by(race) %>%
summarise(N = n()) %>%
ungroup()
glimpse(dat_testsum)
dat_pop <- tibble(
race = c("Asian/Pacific Islander",
"Black", "Hispanic",
"Native American/Native Alaskan", "White"),
N = 331449281 * c(.061, .134, .185, .013, .763))
dat_merge <- merge(dat_plot, dat_testsum)
dat_prop <- dat_merge %>%
mutate(proppop = n / N)
glimpse(dat_prop)
dat_prop %>%
ggplot(aes(x = race, y = education, fill = proppop)) +
geom_tile() +
geom_fit_text(aes(label = round(proppop, 2)), color = "white", size = 10, contrast = TRUE) +
scale_fill_viridis_c() +
coord_fixed()