[R-SIG-Finance] abline() for zoo plot ?

Dirk Eddelbuettel edd at debian.org
Fri Feb 22 21:08:54 CET 2008


On 22 February 2008 at 14:14, Markus Loecher wrote:
| Can you somehow use the convenient abline() function in zoo plots ?
| I am mainly looking for an easy way of adding vertical lines at specific
| locations to my zoo plots.

Take a step back and remember that zoo does all the hard work of plotting
values over ordered observations, presumably dates or times.  So find those
dates and times and use them -- eg either directly via ISOdatetime() or
Date() or from the data.

Example:

> GOOG <- get.hist.quote("GOOG", start=as.Date("2007-01-01"), quote="Close", quiet=TRUE)
> plot(GOOG)
> mi <- which.min(GOOG[,"Close"])
> ma <- which.max(GOOG[,"Close"])
> abline( v=index(GOOG)[mi], col='green')
> abline( v=index(GOOG)[ma], col='red')

As which.min() and which.max() give you indices (ie 'position' in the ordered
obs vector) you need to then use those to index the actual zoo index object.

Hth,  Dirk

-- 
Three out of two people have difficulties with fractions.



More information about the R-SIG-Finance mailing list