【问题标题】:Override y-scale and x-scale using xlim/ylim or xrange/yrange in quantmod::chart_Series() - impossible?在 quantmod::chart_Series() 中使用 xlim/ylim 或 xrange/yrange 覆盖 y-scale 和 x-scale - 不可能?
【发布时间】:2012-06-20 06:07:41
【问题描述】:

我正在尝试在 quantmod::chart_Series() 之上绘制一些支撑/阻力线。问题是有趣的支撑/阻力线在当前时间的系列数据范围之外(低于或高于)(我还想将图表向右扩展一点,超出数据的最后一个时间戳)。

查看 quantmod::chart_Series() 的源代码,我看不到指定 ylim/xlim 的方法,或者在“过去”中使用 quantmod::chartSeries 使用 yrange 覆盖 y-scale 是可能的。在这里评论https://r-forge.r-project.org/scm/viewvc.php?view=rev&root=quantmod&revision=520也证实了我的预感......

我的诊断是否正确,或者是否有一种方法可以在 quantmod::chart_Series 中启用 y 比例覆盖?任何想法如何做我想要的高度赞赏。

谢谢。

最好, 萨摩

【问题讨论】:

    标签: r finance quantmod


    【解决方案1】:

    chart_Series() 注释的帮助页面——三遍! -- 它是实验性的,所以最终的抛光版本可能会有很好的设置这些限制的句柄。

    在那之前,这里有一个 hack(?) 可以让你设置限制并且可以教你一些关于 chart_Series() 工作原理的知识(即通过创建一个环境/关闭类 @987654323 @,它存储了创建图表所需的所有信息)。

    ## 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
    

    【讨论】:

    • 完美。 Thnx 洞察如何做到这一点。
    • 谢谢! chart_Series() 代码很难阅读,因此很高兴看到一些这样的示例。 fixed=T 是什么意思? fixed=F 对 myylim[[2]] 失败,它必须是真的;但是对于更改myxlim,它似乎可以是真或假。还有什么是 myylim[1]?我看到玩它似乎会移动标题,但再次固定可以是真或假!
    猜你喜欢
    • 2021-02-03
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 2014-04-25
    相关资源
    最近更新 更多