-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.R
92 lines (67 loc) · 2.77 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
84
85
86
87
88
89
90
91
92
library("dplyr")
library("plotly")
library("ggplot2")
library("usmap")
incarceration_df <- read.csv("https://raw.githubusercontent.com/vera-institute/incarceration-trends/master/incarceration_trends.csv")
## Chart 1
prison_pop <- read.csv("https://raw.githubusercontent.com/vera-institute/incarceration-trends/master/incarceration_trends.csv", stringsAsFactors = FALSE)
prison_pop_ca <- prison_pop %>%
filter(state == "CA")
prison_pop_ca <- prison_pop_ca %>%
filter((county_name == "Santa Clara County") & (state == "CA"))
prison_pop_ca <- prison_pop_ca %>%
filter(year >= "2000" & year<= "2016")
filtered_data <- prison_pop_ca %>%
group_by(year, county_name)
chart1 <- ggplot(filtered_data, aes(year ,colour = Race)) +
geom_line(aes(y = aapi_prison_pop, color = "Asian/Pacific Islander")) +
geom_line(aes(y = black_prison_pop, color = "Black")) +
geom_line(aes(y = latinx_prison_pop, color = "Latinx")) +
geom_line(aes(y = native_prison_pop, color = "Native American")) +
geom_line(aes(y = white_prison_pop, color = "White")) +
geom_line(aes(y = other_race_prison_pop, color = "Other/Unknown")) +
scale_color_manual(values = c("Black", "Red", "Green", "Blue", "Purple", "Brown")) +
labs(
title = "The Different Population Counts for Different Races in Santa Clara County from 2000 to 2016",
caption = "Source: Vera Institute",
y= "Population",
x = "Year",
scale_x_continuous(breaks = seq(1970,2016, by = 5))
)
ggplotly(chart1)
print(chart1)
# Chart 2
black_prison_pop_ca <- prison_pop %>%
filter(state == "CA")
black_prison_pop_ca <- black_prison_pop_ca %>%
filter(year >= "2000" & year<= "2016")
black_filtered_data <- black_prison_pop_ca %>%
group_by(year, black_jail_pop) %>%
summarize(black_jail_pop = sum(black_jail_pop, na.rm = TRUE))
scatterplot <- ggplot(filtered_data, aes(x = year, y = black_jail_pop)) +
geom_point() +
labs(
title = "Black Prison Populations",
caption = "Source: Vera Institute",
y = "Prison Population",
x = "Year"
)
print(scatterplot)
# Chart 3
us_pop_2018 <- incarceration_df %>%
filter(year == '2018') %>%
group_by(state) %>%
summarize(total_prison_pop = sum(total_jail_pop, na.rm = TRUE))
us_map <- plot_usmap(data = us_pop_2018,
values = 'total_prison_pop',
color = 'black') +
scale_fill_continuous(low = 'white', high = 'red')
labs(
title = "Total Prison Population in US",
caption = "Source: Vera Institute"
)
print(us_map)
#Introduction Values
black_incarc_rate <- mean(incarceration_df$black_jail_pop, na.rm = TRUE) / mean(incarceration_df$total_jail_pop, na.rm = TRUE)
summary_info <- list()
summary_info$black_incar_rate <- mean(incarceration_df$black_jail_pop, na.rm = TRUE) / mean(incarceration_df$total_jail_pop, na.rm = TRUE)