[R] plotting time series

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Apr 28 21:44:54 CEST 2008


ts() only knows about monthly and quarterly series, not biannual ones.
You need to look into methods for irregular series (zoo, its, tseries 
...), or add dates yourself (?plot.POSIXct).  E.g.

> x<-sample (10:100, 17)
> x<-ts(x, start=c(1998,1), frequency=2)
> xtime <- seq(as.Date("1998-05-01"), by="6 months", length=17)
> plot(xtime, x, xaxt="n")
> axis.Date(1, xtime, xtime)

You'll have trouble fitting the dates in, but you could try

> axis.Date(1, xtime, xtime, "%Y %b", las=2, cex=0.7)



On Mon, 28 Apr 2008, eugen pircalabelu wrote:

> Hi List,
>
> I have the following time series and i want to be able to plot it while 
> having the x-axis running from 1998 to 2006 but in a bi-annual format
>
> So here is my example:
>
> x<-sample (10:100, 17)
> x<-ts(x, start=c(1998,1), frequency=2)
> plot(x)
>
> When I plot the ts it goes from 1998 to 2006 by 2years, when in fact i 
> want it to go from 1998 to 2006 with the following form:1998 may, 1998 
> nov, 1999 may, 1999 nov, 2000 may, 2000 nov...... 2005 may, 2005 nov, 
> 2006 may. I have searched nabble for something similar, saw ?plot() but 
> this problem is still a mystery to me .
>
> Thank you and have a great day ahead!

> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list