[R] Axe time of series in format yy-mm-dd

Dirk Eddelbuettel edd at debian.org
Sat Dec 6 20:30:22 CET 2003


On Sat, Dec 06, 2003 at 05:48:06PM -0000, M. M. Palhoto N. Rodrigues wrote:
> I'm trying to plot a ibm stock time series.
> I made the download of that series,
>  ibm <- get.hist.quote(instrument = "ibm",  start = "2003-01-01",quote=c("CL"))
> And  ibm is a serie wiht this characteristic:
> Start = 37623 
> End = 37960 
> Frequency = 1 
> When I try to plot it,
> ts.plot(ibm)
> In the graphic the axe time is represented by  37623 ... 37960, How can I put the time in the format,
> yy-mm-dd ?

As you certainly read the content of 'help(get.hist.quote)', you will know
that the date is stored in Julian days since the 'origin' variable.

So to display dates in a more human-readable format, you need to convert
from Julian dates to a proper date representation and then label the axis
accordingly.  Now, luckily, there are examples -- as e.g. the plotOHLC()
function which is also in the tseries package.  So do 

   > IBM <- get.hist.quote(instrument = "ibm", start='2003-01-01')
   trying URL
   http://chart.yahoo.com/table.csv?s=ibm&a=11&b=31&c=2002&d=11&e=04&f=2003&g=d&q=q&y=0&z=ibm&x=.csv'
   Content type application/octet-stream' length unknown
   opened URL
   .......... .
   downloaded 11Kb

   time series starts 2002-12-30
   time series ends   2003-12-03
   > plotOHLC(IBM)

which works swimmingly for mye on Linux, and displays five dates spanning
from '2002-12-31' to '2003-12-04'.  One caveat: plotOHLC is both a) dog-slow
for larger datasets and b) meaningless as you can't see the open/close ticks
anyway.


Hope this helps,  Dirk

-- 
Those are my principles, and if you don't like them... well, I have others.
                                                -- Groucho Marx




More information about the R-help mailing list