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)
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?
The exact code can be found on github: tidy-forecasting-principles/03-model-methods.Rmd at master · tidyverts/tidy-forecasting-principles · GitHub
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
Thanks a lot @robjhyndman !
system
Closed
July 5, 2020, 10:19am
8
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.