Date on the x-axis in Holt-Winters graph R

◇◆丶佛笑我妖孽 提交于 2020-01-16 05:20:09

问题


I am trying to plot the date as the x-axis in a Holt-Winters graph in R. I have searched for this topic on this site and many others with no luck. I am aware of using xaxt="n" and then axis() for most plots. The following code works for a normal plot:

plot(date,sold, xaxt="n", main="Quantity Widgets Sold")
axis(1,date,format(date,"%d %b", cex.axis=0.7))

so I know the axis function is working properly. However, this approach does not work with the Holt-Winters plot. This is the code I have now:

date<-df$Date
date<-as.Date(date, "%m/%d/%Y")
sold<-df$Quantity.Sold
sold<-ts(sold)

hwsold<-HoltWinters(sold,beta=FALSE,gamma=FALSE)
plot(hwsold, xaxt="n", xlab=NULL)
axis(1,date,format(date,"%d %b", cex.axis=0.7))

The axis is not added to the Holt-Winters plot using this code and the results show only the Holt-Winters filtering plot with no x-axis.

How do I format the Holt-Winters graph so the x-axis shows the date?

Here is sample data:

Date    Quantity.Sold
10/1/2014   14
10/2/2014   44
10/3/2014   23
10/4/2014   12
10/5/2014   9
10/6/2014   17
10/7/2014   18
10/8/2014   24
10/9/2014   35
10/10/2014  13
10/11/2014  23
10/12/2014  17
10/13/2014  19
10/14/2014  25
10/15/2014  29
10/16/2014  41
10/17/2014  37
10/18/2014  13
10/19/2014  16
10/20/2014  12

回答1:


We can specify tick mark locations:

plot(hwsold, xaxt="n", xlab=NULL)
axis(1,c(5,10,15,20),format(date,"%d %b", cex.axis=0.7)[c(5,10,15,20)])



来源:https://stackoverflow.com/questions/36288009/date-on-the-x-axis-in-holt-winters-graph-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!