Last active
December 15, 2021 14:28
-
-
Save StaffanBetner/e4019988ffd6a44f7969cb52fa335e02 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
pacman::p_load(tidyverse, rio, magrittr, janitor, lubridate, gsheet) | |
gsheet2tbl("https://docs.google.com/spreadsheets/d/1BRt-2jMpOBSMwx14JC0RGx6jmDzJCi6KIALV9eSyvtY/edit?usp=sharing") -> timeline | |
timeline %>% | |
mutate(Beginning = Beginning %>% dmy(), | |
End = End %>% dmy) %>% | |
replace_na(replace = list(End = today())) -> | |
timeline | |
factor(timeline$Person, | |
levels = timeline %>% filter(Type=="Statsminister") %>% | |
group_by(Person) %>% | |
summarise(Beginning = min(Beginning)) %>% | |
arrange(Beginning) %>% | |
ungroup %$% Person %>% rev, ordered=TRUE) -> | |
timeline$Person | |
ggplot(data = timeline %>% | |
filter(Type == "Livstid"), | |
aes(x = Person, | |
ymin = Beginning, | |
ymax = End))+ | |
geom_linerange(size = 2.5, color = "#787878", alpha=0)+ | |
geom_rect(data = timeline %>% | |
filter(Type == "Livstid") %>% | |
mutate(rownumber = row_number()), | |
aes(xmin = rownumber-0.5, | |
xmax = rownumber+0.5, | |
ymin = 1800 %>% subtract(30) %>% | |
as.character() %>% | |
parse_date(format = "%Y"), | |
ymax = today() %>% year() %>% add(30) %>% | |
as.character() %>% | |
parse_date(format = "%Y"), | |
fill = factor(rownumber%%2)), | |
inherit.aes = FALSE, | |
alpha = 0.15)+ | |
geom_linerange(size = 2.5, | |
color = "#909090")+ | |
labs(x = NULL, | |
color = NULL, | |
y = NULL, | |
title = "Sveriges statsministrar", | |
caption = "Efter Wikipedia: Sveriges statsminister, @StaffanBetner")+ | |
geom_linerange(data = timeline %>% | |
filter(Type == "Statsminister"), | |
aes(color = Partityp), | |
size = 2.5)+ | |
guides(fill = "none")+ | |
coord_flip(ylim = c(1800, today() %>% year() %>% add(1)) %>% | |
as.character() %>% | |
parse_date(format = "%Y"))+ | |
scale_color_manual(values = c("Center" = "#00b200", | |
"Höger" = "#000099", | |
"Liberal" = "#b2ccff", | |
"Oberoende" = "#ffff00", | |
"Socialdemokratisk" = "#ff0000"))+ | |
scale_fill_manual(values = c("0" = "#4c4c4c", | |
"1" = "#ffffff"))+ | |
geom_hline(yintercept = today(), | |
linetype = "dashed")+ | |
scale_y_date(minor_breaks = seq(1800,2050, 10) %>% | |
as.character() %>% | |
parse_date(format = "%Y"))+ | |
NULL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment