fable: Plot Actual vs Interpolated

library(tsibbledata)
library(tsibble)
library(fable)

actual <- tsibbledata::olympic_running
interpolated <- olympic_running %>% 
  model(lm = TSLM(Time ~ trend())) %>% 
  interpolate(olympic_running)

I would like to replicate the following figures which I got from here.

This post has been edited.

ggplot(data=interpolated,
       mapping=aes(x=Year,y=Time,color=Sex)) +
  facet_wrap(~Length, scales = "free_y") +
  geom_line( linetype=2) +
  geom_line( data=actual,linetype=1)

The exact code can be found on github: https://github.com/tidyverts/tidy-forecasting-principles/blob/master/03-model-methods.Rmd

library(tidyverse)
library(tsibbledata)
library(fable)
#> Loading required package: fabletools

olympic_complete <- olympic_running %>% 
  model(lm = TSLM(Time ~ trend())) %>% 
  interpolate(olympic_running)

olympic_running %>%
  ggplot(aes(x=Year, y = Time, colour = Sex)) +
  geom_line(aes(linetype = "Interpolated"), data = olympic_complete) +
  geom_line(aes(linetype = "Actual")) +
  geom_point(size = 1) +
  facet_wrap(~ Length, scales = "free_y", nrow = 2) + 
  theme_minimal() + 
  scale_color_brewer(palette = "Dark2") + 
  theme(legend.position = "bottom", legend.title = element_blank()) +
  ylab("Running time (seconds)")
#> Warning: Removed 31 rows containing missing values (geom_point).

Created on 2020-06-28 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Thank you for your feedback @nirgrahamuk. Unfortunately, your code does not identify the interpolated points. See the bottom figure. Just to clarify, I would like to visualize actual and interpolated points together. Thanks.

Many thanks @nirgrahamuk! Your code now works as desired. Just one thing: How can I label the linetypes i.e. __ Actual and --- Interpolated?

Thanks a lot @robjhyndman!