library(pacman)
p_load("lubridate",
"ggtext",
"tidyverse")
my_font <- "Avenir Next Condensed"
ggplot2::presidential %>%
mutate(name = ifelse(row_number() == 8, "Bush (HW)", name)) %>%
filter(start > as.Date("1980-01-01")) %>%
mutate(name = as.factor(name),
name = fct_reorder(name, start)) %>%
mutate(diff = lubridate::interval(start, end) %>% as.numeric('years') %>% round(1)) %>%
{
ggplot(.) +
theme_classic() +
# line from start to end
geom_segment(aes(x = start, xend = end, y = name, yend = name),
color = "black", linetype = "dashed", size = 0.8
) +
# start date label
geom_label(aes(x = start, y = name, label = format.Date(start, "%b\n%Y")),
hjust = 0.5, lineheight = 0.85, size = 3.3,
position = position_nudge(x= 100), color = "white",
fill = "turquoise4", family = my_font ) +
# end date label
geom_label(aes(x = end, y = name, label = format.Date(end, "%b\n%Y")),
hjust = 0.5, lineheight = 0.85, size = 3.3,
position = position_nudge(x= -100), color = "white",
fill = "springgreen4", family = my_font ) +
# duration point
geom_point(aes(x = start + ((end - start)/2) , y = name), color = "#e03c00",
size = 4.3, position = position_nudge(y = 0.13) ) +
# duration text
geom_text(aes(x = start + ((end - start)/2) , y = name, label = diff), color = "white",
size = 3.3,position = position_nudge(y = 0.13), family = my_font ) +
scale_x_date(expand = expansion(add = c(1300,1300)),
breaks = paste0(seq.int(
min(.$start) %>% format.Date("%Y"),
max(.$end) %>% format.Date("%Y"),
4), "-01-01" ) %>% as.Date(),
labels = as.character(seq.int(
min(.$start) %>% format.Date("%Y"),
max(.$end) %>% format.Date("%Y"),
4))) +
labs( title = "**One-term or two-term?**",
subtitle = paste(
"<span style='color:#01868B'><b>Start</b></span>,
<span style='color:#008B45'><b>end</b></span>,
and
<span style='color:#e03c00'><b>duration</b></span>,
in years, of each presidential tenure since", .$name[1] ),
x = "",
y = ""
) +
theme(
text = element_text(family = my_font),
plot.title = element_markdown(lineheight = 1.1, hjust = 0),
plot.subtitle = element_markdown(lineheight = 1.1, hjust = 0),
axis.text.y = element_text(face = "bold", color = "black") )
}
