I have a dataset sales_history. Here is a dput
of the first 15 lines
sales_history <- structure(list(month = c("2008/01", "2008/02",
"2008/03", "2008/04", "2008/05", "2008/06", "2008/07",
"2008/08", "2008/09", "2008/10", "2008/11", "2008/12",
"2009/01", "2009/02", "2009/03"),
sales= c(941, 1275, 1908, 2152, 1556,
3052, 2627, 3244, 3817, 3580, 444,
3332, 2823, 3407, 4148 )),
.Names = c("month", "sales"),
row.names = c(NA, 15L),
class = "data.frame")
I have months from 2008/01 until 2013/10. I did auto arima forecast on it by using:
arimaforecast<-function(df)
{
ts1<- ts(df$sales, frequency=12, start=c(2008,1))
fit<-auto.arima(ts1,ic="bic")
plot1=plot(forecast(fit,h=20))
return(plot1)
}
arimaforecast(sales_history)
Then I want to plot the time series. I wrote as below.
y <- ts(sales_history$sales,freq=12,start=c(2011,1),end=c(2013,10))
yt <- window(y,end=c(2013,4))
yfit <- auto.arima(yt,ic="bic")
yfor <- forecast(yfit,h=10)
plot(yfor, main="sales Forecasting", sub="OPTIMAL ARIMA MODEL",
xlab="MONTH", ylab="sales")
lines(fitted(yfor),col="blue")
lines(y,col="red")
Then, the graph turns out to be very ugly. How do I produce a better graph that does the following?
- y-axis does not show as 1e+06, 3e+06, but rather, something like 1M, 3M, etc. And also,
- use green histograms (that is, bars) to show history sales data, while still using lines (with connected dots) to show fitted history and forecasts?
dput(sales_history)
(or a subset of that if it's a lot of data). – sebkopf