library(fpp3)library(tidyverse)# ggplot theme: theme_set(theme_bw() +theme(panel.grid.major =element_blank(),panel.grid.minor =element_blank()))# -- Read in data: --dat <- readxl::read_excel("data/NorwayEmployment_15-74years_bySex.xlsx") %>%as_tibble() %>%mutate(Quarter =str_replace(Quarter, "K","Q"),Quarter =yearquarter(Quarter)) names(dat)[3] <-"Employed"# -- Aggregating from Employed by sex to total --dat <- dat %>%group_by(Quarter) %>%summarize(Employed =sum(Employed)) %>%as_tsibble(index = Quarter) # Time series tabledat %>%autoplot(Employed, colour ="blue")
dat <- dat %>%mutate(`12-MA`= slider::slide_dbl(Employed, mean,.before =5, .after =6, .complete =TRUE),`2x12-MA`= slider::slide_dbl(`12-MA`, mean,.before =1, .after =0, .complete =TRUE) )dat %>%ggplot(aes(x=Quarter, y =Employed))+geom_line(colour ="gray") +geom_line(aes(y =`2x12-MA`), colour ="#D55E00") +theme_bw()+labs(y ="Persons (thousands)",title ="Total employment in US retail")