Quantmod add_TA 和 Chart_Series 出现问题 - 调用下一个 add_TA 后线条和文本消失

发布于 2024-12-23 02:46:19 字数 798 浏览 1 评论 0原文

我经常使用新的 chart_Seriesadd_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诠释孤独 2024-12-30 02:46:19

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文