Quantmod add_TA 和 Chart_Series 出现问题 - 调用下一个 add_TA 后线条和文本消失
我经常使用新的 chart_Series
和 add_TA
。它对我来说非常有效,我发现它非常有用。
我正在尝试在图表上添加一些内容(水平线和一些文本)。这里开始出现问题。正确绘制水平线和文本后,如果我调用后续 add_TA
,它们就会消失...请参阅下面重现问题的示例代码:
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)
这是预期的行为吗?
编辑:如何进行这项工作(根据下面的约书亚评论:重绘绘图对象(chob)时重绘线条和文本)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
add_***
函数向绘图对象 (chob
) 添加信息并重新绘制它。abline
和text
不会将其信息添加到绘图对象中;它们只是绘制到设备,因此当您重新绘制绘图对象时,它们的贡献就会丢失。The
add_***
functions add information to the plot object (chob
) and re-draw it.abline
andtext
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.