I want to replicate the style of tisPlot, from the tis package, in ggplot2. I am having trouble creating the line segments capping both the left and right y-axes in ggplot2. I have attached example code that shows a basic tisPlot along with what I have done to match that style in ggplot2. Does anyone here know how to solve this last part of the problem, namely, adding line segments at the tops of the y-axes? Thanks.
library(tis)
library(tidyverse)
library(lubridate)
set.seed(5)
# make example time-series data
firstTis <- tis(cumsum(rnorm(120)), start = c(1996, 1), freq = 12)
tisPlot(firstTis)
# put example times-series data into a dataframe
df <- data_frame(
date = firstTis %>% time() %>% date_decimal() %>% date(),
firstTis = firstTis %>% as.numeric()
)
ggplot(df) +
geom_line(aes(x = date, y = firstTis)) +
theme_classic() +
theme(
axis.ticks.length = unit(- 7, "pt"),
axis.text.x = element_text(margin = margin(t = 10, b = 0, unit =
"pt")),
axis.text.y = element_text(margin = margin(r = 10, l = 0, unit = "pt"),
color = "white"),
axis.text.y.right = element_text(margin = margin(r = 0, l = 10, unit =
"pt"), color = "black")
) +
scale_y_continuous(sec.axis = dup_axis(name = "")) +