Issue with quantmod add_TA and chart_Series - lines and text disappear after next add_TA is called

拜拜、爱过 提交于 2019-12-19 18:29:10

问题


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:


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.



来源:https://stackoverflow.com/questions/8639928/issue-with-quantmod-add-ta-and-chart-series-lines-and-text-disappear-after-nex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!