After a call to the zooom function (which allows the user to interactively change the zoom of the chart by clicking on the leftmost and rightmost bounds for the zoom), is it possible to get the resulting subset displayed?
The reasons I want this:
- To set an appropriate yrange for my chart based on the custom TAs that I’ve added that would otherwise not be visible, because the automatic yrange is based only the timeseries passed to the original call to chartSeries
- To implement functions to pan the chart left and right
Workarounds for these 2 goals that don’t involve getting the current subset would also be helpful. Currently the only option I can think of is to avoid the use of the interactive zooom function and just use chartZoom.
The first thing to know is why
zoomChart()returns the values you want, butzooom()doesn’t.zoomChart()does because it calls the functionreChart(), which ends with the lineinvisible(chob). (chobis the name of the object you’re after.)zooom()doesn’t do this. It callszoomChart(), but it doesn’t arrange to passchobout of the environment within whichzoomChart()is being evaluated. You can do that, though, by creating a modified version ofzooom()I did this by first dumping
zooomto a file and then creating an edited function calledzooom2:The three edits I made were:
Replace calls to
get.chob()with calls toquantmod:::get.chob(). This is needed because, unlikezooom,zooom2does not havenamespace:quantmodas its enclosing environment.Assign the output of
zoomChart()to the objectchob.Return
chobto the calling environment by ending the function withinvisible(chob).Here’s the modified function:
You can source or paste the function back into your R session, and then use it like this (for example):
If this is something that’s useful to you, you might want to add it to the
quantmodsources, and recompile your own version of the package.Hope this helps.