Hi Experts,
Need help on r for forecasted line chart, Please find the attachment for details.
Issue:
-
As of now, x axis has 2017.0, 2017.5 But I need dynamically plotting for x axis yearmonth like 201701,201702, etc.
-
Need plotting value i.e population value on chart including the forecasted value.
Below is the code used for chart:
library(forecast)
ord <- order(ds$`Year`,ds$`Month`)
sds <- ds[ord,]
fRec <- sds[1,]
mon <- as.numeric(firstRec$'Month')
yrs <- as.numeric(as.character(firstRec$'Year'))
tm <- ts(data = sds$Population , start= c(yrs,mon) ,frequency = 12)
plot(tm)
tm[is.na(tm)] <-0
hw <- HoltWinters(tm)
plot(forecast(hw,h=3))
Below is sample data:
Month,Year,YearMonth,Population
1,2017,201701,100
1,2018,201801,300
2,2018,201802,310
3,2018,201803,320
4,2018,201804,330
2,2017,201702,200
3,2017,201703,300
4,2017,201704,400
5,2017,201705,500
6,2017,201706,600
7,2017,201707,700
8,2017,201708,800
9,2017,201709,900
10,2017,201710,1000
11,2017,201711,1100
12,2017,201712,1200
Thanks,
Red