library(magrittr); library(dplyr); library(ggplot2)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Norm = readRDS("rguservice.lm.pred.cones.r")
Let’s see what’s in here:
Norm %>% names()
## [1] "model" "mean" "lower" "upper" "level"
## [6] "x" "series" "method" "newdata" "residuals"
## [11] "fitted"
Norm %>% class()
## [1] "forecast"
Norm %>% lapply(class)
## $model
## [1] "tslm" "lm"
##
## $mean
## [1] "ts"
##
## $lower
## [1] "mts" "ts" "matrix"
##
## $upper
## [1] "mts" "ts" "matrix"
##
## $level
## [1] "numeric"
##
## $x
## [1] "ts"
##
## $series
## [1] "character"
##
## $method
## [1] "character"
##
## $newdata
## [1] "data.frame"
##
## $residuals
## [1] "ts"
##
## $fitted
## [1] "ts"
So it looks like the objects we want are ‘mean’, ‘lower’ and ‘upper’.
ggplot() + geom_line(data = Norm$mean, aes(x = x, y = y)) + geom_smooth(data = Norm$lower, aes(x = x, y = y), color = "red") + geom_smooth(data = Norm$upper, aes(x = x, y = y), color = "green") + xlab("Year") + ylab("Value")
## `geom_smooth()` using method = 'loess'
## `geom_smooth()` using method = 'loess'