Quantmod add_TA和chart_Series的问题-调用下一个add_TA之后,行和文本消失 [英] Issue with quantmod add_TA and chart_Series - lines and text disappear after next add_TA is called

查看:112
本文介绍了Quantmod add_TA和chart_Series的问题-调用下一个add_TA之后,行和文本消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在大量使用新的chart_Seriesadd_TA.它对我来说很好用,我觉得它很有用.

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

我正在尝试在图形上添加一些内容(水平线和一些文本).在这里开始出现问题.正确绘制水平线和文本后,如果我调用后续的add_TA ...,它们会消失.请参见下面的示例代码,该代码会重现该问题:

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)

这是预期的行为吗?

如何进行这项工作(根据约书亚下面的评论:当重绘绘图对象(chob)时,还要重绘线条和文字)?

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

推荐答案

add_***函数将信息添加到绘图对象(chob)并重新绘制. ablinetext不会将其信息添加到绘图对象;它们只是绘制到设备上,因此当您重新绘制图形对象时,它们的贡献就会丢失.

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.

这篇关于Quantmod add_TA和chart_Series的问题-调用下一个add_TA之后,行和文本消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆