[R-SIG-Finance] Using abline with chartSeries

Joshua Ulrich josh.m.ulrich at gmail.com
Mon Apr 9 07:58:24 CEST 2012


On Sun, Apr 8, 2012 at 10:24 PM, Worik Stanton <worik.stanton at gmail.com> wrote:
> On 08/04/12 14:39, Joshua Ulrich wrote:
>>
>> Use rseek.org instead of Google (it provides a custom Google search).
>> The answer to your question is the first result under "support lists"
>> when you search for "chartseries vertical line".
>>
>> chartSeries(IBM.m)
>> addTA(.xts(TRUE,.index(IBM.m)[24]), on=1)
>>
> Actually, no.  As an experiment I used your advice, on rseek.org,  and have
> not come across this.  "chartseries" matches "chart series" (without the
> quotes) so any useful advice is burried under a mountain of unhelpful
> advice.
>
Then you're doing something wrong.  Here's the search:
http://www.rseek.org/?cx=010923144343702598753%3Aboaz1reyxd4&q=chartseries+vertical+line&sa=Search+functions%2C+lists%2C+and+more&cof=FORID%3A11&siteurl=rseek.org%2F&ref=

Click the "Support Lists" tab on the right section of the page.  The
first three results answer your original question.

> Using google and looking for "chartSeries quantstrat abline" (again without
> quotes) I found
> http://www.r-bloggers.com/great-faj-article-on-statistical-measure-of-financial-turbulence-part-3/
> that advised....
>
> chartSeries(turbulence,theme="white",name="Correlation and % Change as
> Measure of Financial Turbulence")
> abline(h=0.8)
>
> So  again tried...
>
>> getSymbols("IBM")
> [1] "IBM"
>> IBM.m <- to.monthly(IBM)
>> chartSeries(IBM.m, theme="white")
>> abline(h=160)
>
> But the horizontal line is *not* at 160, unless the y-axis is wrong.
>
That's because his chart didn't have a lower graph; yours does.  Try:
chartSeries(IBM.m, TA=NULL)
abline(h=160)

Note that the line drawn by abline won't be kept if you make any
future call to an add* function because abline doesn't alter the
underlying chartSeries object (chob), so all changes will be lost if
the plot has to be re-drawn.

> So how is it done?
>
Nearly the same way as I showed you how to add a vertical line to a
chartSeries plot.

chartSeries(IBM.m)
addTA(.xts(rep(160,nrow(IBM.m)),.index(IBM.m)), on=1)

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

R/Finance 2012: Applied Finance with R
www.RinFinance.com



More information about the R-SIG-Finance mailing list