X axis in DateTime format in R script/plot -


i trying build forecast plot in r. but, inspite of trying many solutions unable plot x axis in dates.

my data in form of :

datetime(mm/dd/yyy) consumedspace 01-01-2015          2488 02-01-2015          7484 03-01-2015          4747 

below forecast script using:

library(forecast) library(calibrate) # group searches date dataset <- aggregate(consumedspace ~ date, data = dataset, fun= sum) # create time series based on day of week ts <- ts(dataset$consumedspace, frequency=6) # pull out seasonal, trend, , irregular components time series (train forecast model) decom <- stl(ts, s.window = "periodic") #predict next 7 days of searches pred <- forecast(decom) # plot forecast model plot(pred) #text(pred,ts ,labels = dataset$consumedspace) 

the output looks this-- can see have x axis displayed periods(numbers) rather in data format. enter image description here

any highly appreciated.

  • try enter explicit specifications in plot : plot(x=date, ...)
  • if not work try :

    timeline<-seq(from=your.first.date, to=your.last.date, by="week")
    plot(x=...,y=..., xlab=na, xaxt="n") # no x axis axis.date(1, at=(timeline), format=f, labels=true) # special axis

edit : sorry first solution, not fit timeserie. problem there no date time series, index refering "start" , "frequency". here, problem comes use of "frequency", supposed specify number of observations unit of time, ie 4 quarterly data, 12 monthly data... here unit of time week, 6 open days, that's why graph axes indicates index ok weeks. have more readable axis can try :

dmin<-as.date("2015-01-01")    # starting date # dummy data consumedspace=rep(c(5488, 7484, 4747, 4900, 4747, 6548, 6548, 7400, 6300, 8484, 5161, 6161),2)  ts<-ts(consumedspace, frequency=6) decom <- stl(ts, s.window = "periodic") pred <- forecast(decom)  plot(pred, xlab=na, xaxt="n")   # plot no axis ticks<-seq(from=dmin, to= dmin+(length(time(pred))-1)*7, = 7) # ticks sequency : ie weeks label axis(1, at=time(pred), labels=ticks) # axis weeks label @ weeks index 

you have use 7 interval weeks labels because of closed day. it's ugly works. there surely better way looking closely @ ts() specify data daily data, , adapting forecasting function.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -