在R中滚动图表窗口

时间:2012-10-17 15:50:06

标签: r charts scroll

我想从R创建一个比显示区域大的图表。即数千个数据点(如股票图表)。我希望能够在图表中左右滚动。是否有任何功能或包已知可以做到这一点?

我在这里和网上都有各种各样的seraches,但我不能为R找到任何东西,因为我不得不去编写一些相当严肃的东西。

不要寻找除此之外的任何东西。

2 个答案:

答案 0 :(得分:3)

以下是使用TeachingDemos包中的tkexamp函数的一种方法:

library(TeachingDemos)

my.x <- seq(1,10000)
my.y <- 5 + my.x/3000 + sin(my.x/1000) + rnorm(10000,0,.5)

myfun <- function(x,y,start=1, span=100, 
    xlab=deparse(substitute(x)), 
    ylab=deparse(substitute(y)),...) {
    w <- seq(start, length.out=span)
    w <- w[ w<= length(x) ]
    plot(x[w],y[w], main=paste(start,'to',max(w)), 
    ylim=range(y), xlab=xlab, ylab=ylab, ... )
}


mylist <- list( start=list('slider', from=1, to=10000, init=1),
                span=list('slider', from=10, to=10000, 
                    init=100, resolution=10) )

tkexamp( myfun(my.x,my.y,type='b'), mylist )

答案 1 :(得分:0)

“奇特”但简单的解决方案是使用R Shiny with Highstocks的quantmod。

使用Stefan Wilhelm's "Using Highstocks in R Shiny apps"查看full code on Github

快速预览how scrolling works

Highstocks真的很花哨。 : - 。)