简体   繁体   English

在quantmod :: chart_Series()中使用xlim / ylim或xrange / yrange覆盖y-scale和x-scale-不可能吗?

[英]Override y-scale and x-scale using xlim/ylim or xrange/yrange in quantmod::chart_Series() - impossible?

I am trying to plot some support/resistance lines on top of quantmod::chart_Series(). 我试图在quantmod :: chart_Series()顶部绘制一些支撑/阻力线。 The issue is that the interesting support/resistance lines are outside (below or above) series data range up to current time (I would also like to extend a chart a bit to the right beyond last timestamp of data). 问题是,直到当前时间为止,有趣的支撑线/阻力线都在系列数据范围之外(之下或之上)(我也想将图表扩展到最后一个数据时间戳的右边)。

Looking at the source code of quantmod::chart_Series() I can see no way of specifying ylim/xlim or, what was possible in "the old days" with quantmod::chartSeries using yrange to override y-scale. 看一下quantmod :: chart_Series()的源代码,我看不到指定ylim / xlim的方法,或者在使用yrange覆盖y-scale的quantmod :: chartSeries的“旧时代”中可能实现的目标。 Comment here https://r-forge.r-project.org/scm/viewvc.php?view=rev&root=quantmod&revision=520 is also comfirming my hunch... 在这里评论https://r-forge.r-project.org/scm/viewvc.php?view=rev&root=quantmod&revision=520也证实了我的直觉...

Is my diagnosis correct or is there maybe a way that enables y-scale overriding in quantmod::chart_Series? 我的诊断是正确的,还是有可能在quantmod :: chart_Series中启用y比例覆盖? Any idea how to do what I want highly appreciated. 任何想法如何做我想要的高度赞赏。

Thanks. 谢谢。

Best, Samo 最好,萨摩

The help page for chart_Series() notes -- three times! chart_Series()注释的帮助页面-三次! -- that it is experimental, so presumably the eventual polished version will have nice handles for setting these limits. -这是实验性的,因此最终的抛光版本可能会设置这些限制。

Until then, here is a hack(?) that will let you set the limits and may teach you something about how chart_Series() works (ie by creating an environment/closure of class "replot" , which stores all of the info needed to create a chart plot). 在此之前,这里有一个hack(?),它可以让您设置限制, 可以教您一些有关chart_Series()工作方式的信息(即,通过创建类"replot"的环境/闭包来存储所有需要的信息)创建图表)。

## Create an example plot
getSymbols("YHOO")
myChob <- chart_Series(YHOO)

## Plot it, with its default xlim and ylim settings
myChob


## Get current xlim and ylim settings for `myChob` (chob = chart object)
myxlim <- myChob$get_xlim()
myylim <- myChob$get_ylim()

## Alter those limits
myxlim <- c(1, 2000)
myylim[[2]] <- structure(c(0, 50), fixed=TRUE)

## Use the setter functions in the myChob environment to set the new limits.
## (Try `myChob$set_ylim` and `ls(myChob$Env)` to see how/where these are set.)
myChob$set_ylim(myylim)
myChob$set_xlim(myxlim)

## Plot the revised graph
myChob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM