Re: [R] plotting time series

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 28 Apr 2008 20:44:54 +0100 (BST)

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@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

______________________________________________
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.
Received on Mon 28 Apr 2008 - 20:35:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Apr 2008 - 21:31:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive