r - Add vertical lines to quantmod::chart_Series -
i want add vertical lines on several dates on graph. far haven't managed achieve simple task. 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 have read here, know abline
not supposed work new chart_series
function. doesn't seem work anyway. addlines
function not work in of forms tried - plain addlines
, plot(addlines(...))
, chart_series(..., ta="addlines(...)")
or add_ta("addlines(...)")
.
i need use experimental version of quantmod because solved other problems had old version. d1
list of dates.
you can't mix functions old , new versions of quantmod's charting functions. if want use addlines
, have use chartseries
. if use addlines
, chartseries
, d1
should xts object, not datetime object. example:
library(quantmod) data(sample_matrix) s <- as.xts(sample_matrix) chartseries(s,ta="addlines(v=s[100])")
if want add vertical line using chart_series
, create logical xts object true
values want lines appear , false
otherwise. example:
l <- xts(!as.logical(s[,1]),index(s)) l[100] <- true chart_series(s,ta="add_ta(l,on=1)")
also note can put vertical line "behind" chart using on=-1
in add_ta
call:
chart_series(s,ta="add_ta(l,on=-1,col='grey',border='grey')")
Comments
Post a Comment