R中的实时,自动更新,增量图

use*_*176 19 plot r real-time

我正试图制作一个动态的情节,有点像自动更新,增量,可能是实时.我想完成这样的事情 http://www.youtube.com/watch?v=s7qMxpDUS3c

这就是我到目前为止所做的.假设您在data.frame中有一个名为temp的时间序列.第一列是时间,第二列是值的位置.

for(i in 1: length(temp$Time[1:10000]))
{
flush.console()
plot(temp$Time[i:i+100],temp$Open[i:i+100],
xlim=c(as.numeric(temp$Time[i]),as.numeric(temp$Time[i+150])),
ylim=c(min(temp$Open[i:i+100]),max(tmep$Open[i:i+120])))
Sys.sleep(.09)
}
Run Code Online (Sandbox Code Playgroud)

这确实是逐步绘制的,但我没有获得100个单位的长时间序列,而是只获得一个点更新.

nog*_*pes 26

你想做这样的事吗?

n=1000
df=data.frame(time=1:n,y=runif(n))
window=100
for(i in 1:(n-window)) {
    flush.console()
    plot(df$time,df$y,type='l',xlim=c(i,i+window))
    Sys.sleep(.09)
}
Run Code Online (Sandbox Code Playgroud)

浏览你的代码:

# for(i in 1: length(temp$Time[1:10000])) { 
for (i in 1:10000) # The length of a vector of 10000 is always 10000
    flush.console()
    # plot(temp$Time[i:i+100],temp$Open[i:i+100],
    # Don't bother subsetting the x and y variables of your plot.
    # plot() will automatically just plot those in the window.
    plot(temp$Time,temp$Open, 
    xlim=c(as.numeric(temp$Time[i]),as.numeric(temp$Time[i+150]))
    # Why are you setting the y limits dynamically? Shouldn't they be constant?
    # ,ylim=c(min(temp$Open[i:i+100]),max(tmep$Open[i:i+120])))
    Sys.sleep(.09)
}
Run Code Online (Sandbox Code Playgroud)

  • 天哪,你是我的最爱!我男子气概爱你!这正是我想要完成的.谢谢大师.回答你的上一个问题.它不是恒定的,因为它们是第二数据的开放价格? (2认同)