[R-SIG-Finance] Modify the chart object to save plotted text

Brian G. Peterson brian at braverock.com
Thu Apr 19 02:55:59 CEST 2012


On Wed, 2012-04-18 at 19:45 -0500, Joshua Ulrich wrote:
> > chart_Series(SPY)
> > x <- SPY["2012-02-15", which.i=TRUE]
> > text(x, Lo(SPY)[x,], "2012-02-15", srt=90, adj=c(1,0.5) )
> >
> >
> > And now when I add this TA the text disappears:
> >
> > add_TA(Cl(SPY)<134,border=NA,col='#888888',on=-1)
> >
> > I think this probably requires going under the hood in the library,
> so a pointer on where to begin looking would be greatly appreciated.
> >
> I'm not familiar with the internals of chartSeries or chart_Series, so
> I can only provide a pointer.  Look at add_TA to see how it gets the
> current plot object and adds to it.

chartSeries and chart_Series actually re-render the chart, and keep
internal state.  text() writes on top of the existing plot object, but
its state isn't maintained when the chart is re-drawn.

So, the simplest thing to do is to overplot your text *last* or plot it
into a persistent device like pdf().

Barring that, Josh is right, and you'd want to modify add_TA to create
an add_Text() function that would store its state with the chob.

Cheers,

    - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list