Created
January 7, 2022 18:31
-
-
Save mfherman/6042edc9e2986fbb5052131b3b9530e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
df <- tribble( | |
~agency, ~offense, ~type, ~date, | |
"Agency A", "Drug", "sentence_dt", as.Date("2016-01-04"), | |
"Agency A", "Person", "sentence_dt", as.Date("2017-07-01"), | |
"Agency A", "Drug", "start_dt", as.Date("2016-04-04"), | |
"Agency A", "Drug", "end_dt", as.Date("2018-12-09"), | |
"Agency B", "Person", "sentence_dt", as.Date("2017-01-30"), | |
"Agency B", "Person", "start_dt", as.Date("2017-01-30"), | |
"Agency B", "Person", "end_dt", as.Date("2019-07-01"), | |
"Agency C", "Drug", "sentence_dt", as.Date("2019-06-10"), | |
"Agency C", "Property", "sentence_dt", as.Date("2019-10-26"), | |
"Agency C", "Drug", "start_dt", as.Date("2019-06-10"), | |
"Agency C", "Drug", "end_dt", as.Date("2021-04-01") | |
) %>% | |
mutate(agency = fct_rev(agency)) | |
df %>% | |
ggplot() + | |
geom_line( | |
aes(date, agency), | |
size = 18, color = "gray75", | |
lineend = "round", | |
alpha = 0.8 | |
) + | |
geom_point( | |
data = filter(df, type == "sentence_dt"), | |
aes(date, agency, color = offense, shape = offense), | |
size = 8 | |
) + | |
labs( | |
x = NULL, | |
y = NULL, | |
color = "Offense type", | |
shape = "Offense type" | |
) + | |
scale_x_date(breaks = "1 year", date_labels = "%Y") + | |
theme_minimal() + | |
theme( | |
panel.grid.major.y = element_blank(), | |
panel.grid.minor.x = element_blank(), | |
axis.text = element_text(size = 14), | |
plot.margin = margin(20, 20, 20, 20), | |
legend.position = "top", | |
legend.justification = c(0, 0) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment