Learning Programming in R – Next
global_temp <- read.csv(“datasets/global_temperature.csv”)
plot(global_temp$year, global_temp$degrees_celsius,
type = “l”, col = “forestgreen”,
xlab = “year”, ylab = “degrees celsius”)
======================================
The autoplot function from ggplot2
library(forecast)
library(ggplot2)
# Converting global_temp into a time series (ts) object.
global_temp_ts <- ts(global_temp$degrees_celsius,
start = global_temp$year[1])
# Forecasting global temperature 50 years into the future
# using an exponential smoothing state space model (ets).
temperature_forecast <- forecast( ets(global_temp_ts), h = 50)
# Plotting the forecast
autoplot(temperature_forecast)
======================================
最新評論