I want to add vertical lines on several dates on a certain graph. So far I haven't managed to achieve this simple task. This is what I tried:
> s <- get(getSymbols('nvmi'))["2012::"]
> d1 <- index(s[100])
> d1
[1] "2012-05-24"
> chart_Series(s,TA="addLines(v=d1)")
Error in get.current.chob() : improperly set or missing graphics device
> chart_Series(s)
> abline(v=d1)
# nothing
> add_TA("addLines(v=d1")
Error in `[.data.frame`(lenv$xdata, Env$xsubset) :
undefined columns selected
From what I have already read here, I know that abline
is not supposed to work with the new chart_Series
function. It doesn't seem to work anyway. The addLines
function does not work in any of the forms I tried - plain addLines
, plot(addLines(...))
, chart_Series(..., TA="addLines(...)")
or add_TA("addLines(...)")
.
I need to use the experimental version of quantmod because it solved other problems I had with the old version. d1
would eventually be a list of dates.
You can't mix functions from the old and new versions of quantmod's charting functions. If you want to use
addLines
, you have to usechartSeries
. Even if you useaddLines
andchartSeries
,d1
should be an xts object, not a datetime object. For example:If you want to add a vertical line using
chart_Series
, create a logical xts object withTRUE
values where you want the lines to appear andFALSE
otherwise. For example:Also note that you can put the vertical line "behind" the chart by using
on=-1
in theadd_TA
call:add horizontal line my example:
enter image description here