forked from f-edwards/cps_lifetables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_state_vis.r
110 lines (97 loc) · 3.17 KB
/
make_state_vis.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
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
library(tidyverse)
library(maps)
library(usmap)
tables_comb<-read_csv("./vis/st_tables.csv")
map_dat<-us_map()
state_dat<-tables_comb %>%
left_join(map_dat %>%
rename(state=abbr)) %>%
arrange(order, group)
ggplot(tables_comb,
aes(x = c_mn, fill = race_ethn, color = race_ethn)) +
geom_density(alpha = 0.2) +
facet_wrap(~varname, scales = "free") +
theme_bw()+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
legend.title = element_blank()) +
ylab("Cumulative risk") +
ylab("Risk of event by age 18") +
theme_minimal() +
ggsave("./vis/st_race_density.png")
state_dat<-state_dat %>%
mutate(race_ethn = ifelse(race_ethn=="Hispanic",
"Latinx",
race_ethn)) %>%
mutate(race_ethn = factor(race_ethn,
levels = c(
"Total",
"AI/AN",
"Asian/PI",
"Black",
"Latinx",
"White")))
ggplot(state_dat %>%
filter(varname=="Investigation"),
aes(x=x, y = y, group = group, fill = c_mn)) +
geom_polygon() +
geom_polygon(color = "black") +
theme_void() +
labs(fill = "") +
theme(legend.position = "bottom") +
scale_fill_distiller(palette = "Spectral") +
facet_wrap(~race_ethn) +
ggsave("./vis/st_race_investigation.png")
ggplot(state_dat %>%
filter(varname=="Confirmed Maltreatment"),
aes(x=x, y=y, group = group, fill = c_mn)) +
geom_polygon() +
geom_polygon(color = "black") +
theme_void() +
labs(fill = "") +
theme(legend.position = "bottom") +
scale_fill_distiller(palette = "Spectral") +
facet_wrap(~race_ethn) +
ggsave("./vis/st_race_malt.png")
ggplot(state_dat %>%
filter(varname=="Foster Care"),
aes(x=x, y=y, group = group, fill = c_mn)) +
geom_polygon() +
geom_polygon(color = "black") +
theme_void() +
labs(fill = "") +
theme(legend.position = "bottom") +
scale_fill_distiller(palette = "Spectral") +
facet_wrap(~race_ethn) +
ggsave("./vis/st_race_fc.png")
ggplot(state_dat %>%
filter(varname=="Termination of Parental Rights"),
aes(x=x, y=y, group = group, fill = c_mn)) +
geom_polygon() +
geom_polygon(color = "black") +
theme_void() +
labs(fill = "") +
theme(legend.position = "bottom") +
scale_fill_distiller(palette = "Spectral") +
facet_wrap(~race_ethn) +
ggsave("./vis/st_race_tpr.png")
### make tpr/investigation ratio
tpr_dat<-state_dat %>%
filter(grepl("Termination", varname)) %>%
rename(tpr=c_mn) %>%
select(-se_tot, -c_upr, -c_lwr, -varname)
ratio_dat<-state_dat %>%
filter(grepl("Investigation", varname)) %>%
left_join(tpr_dat) %>%
mutate(tpr_ratio = tpr/c_mn)
ggplot(ratio_dat,
aes(x=x, y=y, group = group, fill = tpr_ratio)) +
geom_polygon() +
geom_polygon(color = "black") +
theme_void() +
labs(fill = "") +
theme(legend.position = "bottom") +
scale_fill_distiller(palette = "Spectral") +
facet_wrap(~race_ethn) +
ggsave("./vis/st_race_tpr_ratio.png")