I want to create a plot (preferable using ggplot2
) where I visualize a timeline together with a time-trend plot.
To put it in a practical example, I have aggregated unemployment rates for each year. I also have a data set denoting important legislation changes that are related to the labor market. Hence, I want to create a timeline where the unemployment rate is shown following the same x-axis (time).
I have generated some toy-data, see code below:
set.seed(2110)
year <- c(1950:2020)
unemployment <- rnorm(length(year), 0.05, 0.005)
un_emp <- data.frame(cbind(year, unemployment))
year <- c( 1957, 1961, 1975, 1976, 1983, 1985, 1995, 1999, 2011, 2018)
events <- c("Implemented unemployment benefit",
"Pre-school became free",
"Five-day workweek were introduced",
"Labor law reform 1976",
"Unemployment benefit were cut in half",
"Apprenticeship Act allows on-the-job training",
"Changes in discrimination law",
"Equal Pay for Equal Work was",
"9 weeks vacation were introduced",
"Unemployment benefit were removed")
imp_event <- data.frame(year, events)
I can easily plot the time-trend across the years:
library(tidyverse)
ggplot(data = un_emp, aes(x = year, y = unemployment)) +
geom_line(color = "#FC4E07", size = 0.5) +
theme_bw()
But how do I include the events (found in imp_event
) in the plot in a nice and efficient way? How can I do this?
My aim is to make a timeline looking like the one from here but to combine it with the time-trend plot shown above. How can I do this?
I have tried to use vline
but I cannot add the label of the event.
Thanks!