I am trying to produce a ggplot graph where I can compare two time periods without indexing the data. So, that I get one time-window running along the x-axis at the bottom and one along the x-axis at the top, kinda like the the example from the tidyverse manual page (see graph at bottom of linked page).
However I would like to have dual axis on the y-axis too, something like this (made this by copy-pasiting using the code below),

economics_long %>% filter(variable== "pce" & date > "2008-01-01" & date < "2010-01-01") %>%
ggplot(aes(date, value01, colour = variable)) + geom_line()
economics_long %>% filter(variable== "pce" & date > "1990-01-01" & date < "1992-01-01") %>%
ggplot(aes(date, value01, colour = variable)) + geom_line()
I imagine I would need to use bind_rows() to cut the two time periods out and put them on top and maybe make a new variables like variable with two options, like time-window 1 and time-window 2, however I wanted to ask here before I start manually build something crazy. Maybe others have done something simular?
I have made some first steps, like,
tw01 <- economics_long %>%
filter(variable== "pce" & date > "2008-01-01" & date < "2010-01-01")
tw02 <- economics_long %>%
filter(variable== "pce" & date > "1990-01-01" & date < "1992-01-01")
tw02$date <- tw01$date
tw <- bind_rows(tw01, tw02, .id = "time_window")
tw %>% ggplot(aes(date, value01, colour = time_window)) + geom_line()
Maybe this is what you are looking for:
lubridate::years. Addtionally for the transformation insidesec_axisI to wrap intohms::hmsas I otherwise got an error.theme()adjustemnts.