forked from EvaMaeRey/ggplot_flipbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_incarceration.Rmd
89 lines (67 loc) · 2.65 KB
/
05_incarceration.Rmd
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
name: incarcerationbysex
# Incarceration
This visualization is a sobering one --- showing incarceration rates across different demographics over time. The data comes via #TidyTuesday via the Vera Institute of Justice. My strategy is pretty simple - to show changes in rates over time for different groups using facet grid.
```{r, echo = F}
dir <- "raw_data"
file <- paste0(dir, "/", "prison_summary.csv")
url <- "https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-01-22/prison_summary.csv"
# create raw_data folder
if (!dir.exists(dir)) { dir.create(dir) }
# download data from internet and save
if (!file.exists(file)) { download.file(url = url, destfile = file) }
# read in downloaded data
df <- readr::read_csv(file)
```
```{r, echo = F}
data <- df %>%
filter(pop_category %in% c("Female", "Male"))
```
A random sample from the data set:
```{r, echo = F}
knitr::kable(head(data, 5), format = "html")
```
---
```{r incarceration_01, eval=F, echo=F}
ggplot(data = data) +
aes(x = year, y = rate_per_100000) +
geom_line() +
facet_grid(urbanicity ~ pop_category) +
theme_minimal(base_family = "Times") +
labs(x = "", y = "Incarcerated per 100000") +
labs(subtitle = "Data source: Vera Institute of Justice") +
labs(title = "Incarceration rates by sex and urbanicity in the US, 1983-2015")
```
```{r, echo = F, warning=F, message=F, eval = T, fig.show='hide'}
get_what_save_what <- "incarceration_01"
eval(parse(text = paste(knitr:::knit_code$get(get_what_save_what), collapse = "")))
ggsave(paste0("figures/", get_what_save_what, ".png"), dpi = 300)
```
`r apply_reveal("incarceration_01")`
---
name: incarcerationbygender
```{r, echo =F}
dat <- df %>%
filter(!(pop_category %in% c("Female", "Male", "Total", "Other")))
```
A random sample from the data set:
```{r, echo = F}
knitr::kable(head(dat, 5), format = "html")
```
---
```{r incarceration_02, eval=F, echo=F}
ggplot(data = dat) +
aes(x = year, y = rate_per_100000) +
geom_line() +
facet_grid(urbanicity ~ pop_category) +
theme_minimal(base_family = "Times") +
labs(x = "", y = "Incarcerated per 100000") +
labs(subtitle = "Data source: Vera Institute of Justice") +
labs(title = "Incarceration rates by race/ethnicity and urbanicity in the US, 1983-2015")
```
```{r, echo = F, warning=F, message=F, eval = T, fig.show='hide'}
get_what_save_what <- "incarceration_02"
eval(parse(text = paste(knitr:::knit_code$get(get_what_save_what), collapse = "")))
ggsave(paste0("figures/", get_what_save_what, ".png"), dpi = 300)
```
`r apply_reveal("incarceration_02")`
---