Issue with quantmod add_TA and chart_Series - line

2019-02-22 10:31发布

I am using new chart_Series and add_TA quite a lot. It works very well for me and I find it very useful.

I am trying to add a few things (horizontal lines and some text) on a graph. Here problems start to occur. After horizontal lines and text are drawn correctly they disappear if I call subsequent add_TA... Please see the example code below which reproduces the problem:

library(quantmod)

getSymbols("SPY")

dev.new()
chart_Series(SPY)
add_TA(ADX(HLC(SPY))$ADX)
abline(h=15, col="red")
abline(h=35, col="green")
text(10, 7, "Text and horizontal lines disappear after next add_TA is called",
  col="blue", cex=0.8, adj = c(0,0))
# run the code up to this point (including text(...
# see how horizontal lines drawn with abline and text is displayed correctly
# now run the last line by adding additional TA and you will see that lines
# and text disappears
add_TA(DVI(Cl(SPY))$dvi)

Is this intended behavior?

EDIT: How to make this work (as per Joshua comment below: redrawing also line and text when plot object (chob) is being redrawn)?

1条回答
放荡不羁爱自由
2楼-- · 2019-02-22 10:49

The add_*** functions add information to the plot object (chob) and re-draw it. abline and text do not add their information to the plot object; they just draw to the device, so their contributions are lost when you re-draw the plot object.

查看更多
登录 后发表回答