I have data in tsibble format that I labelled tsdb:
A tsibble: 15,000 x 6 [1M]
# Key: Industry [60]
# Groups: Industry [60]
Industry Period Sales inventory Purchase Sales.diff
<chr> <mth> <dbl> <dbl> <dbl> <dbl>
1 Apparel manufacturing 2000 Feb 5321 12215 5228 NA
I needed to make plots grouped by industry and so I wrote this code for one industry:
tsdb %>%
filter(Industry == "Manufacturing industries") %>%
pivot_longer(c(Sales, inventory, Purchase), names_to = "Series", values_to = "Million_Dollars") %>%
ggplot(aes(x = Period, y = Million_Dollars, color = Series)) +
geom_line() +
facet_grid(vars(Series), scales = "free_y") +
ggtitle("Manufacturing industries") +
theme(plot.title = element_text(hjust = 0.5))
This works fine and I get this plot

I want to add vertical lines in all the three graphs at select points say "2005 May" and "2008 Jun". To do this, I tried adding:
geom_vline(xintercept = yearmonth("2005 May"), linetype = 4) +
and I get this error
Error in UseMethod("rescale") :
no applicable method for 'rescale' applied to an object of class "c('yearmonth', 'vctrs_vctr')"
I even tried:
geom_vline(xintercept = yearmonth(424), linetype = 4) +
geom_vline(xintercept = scale_x_yearmonth(424), linetype = 4) +
geom_vline(xintercept = scale_x_yearmonth("2005 May"), linetype = 4) +
And I get the error here as:
Error in xj[i] : object of type 'environment' is not subsettable
I guess the yearmonth needs to be scaled for ggplot to understand, but I’m not sure how to do this. I was trying to get one vertical line and then was hoping that I could use c() and get all the vertical lines that I need. My objective is to get the vertical lines by specifying the time period, e.g. "2005 May".