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

标签 r plot real-time

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

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

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)
}


这的确是增量绘制的,但我没有得到100个单位的长时间序列,相反,我只得到了一点更新。

最佳答案

你想做这样的事情吗?

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)
}


查看您的代码:

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

关于r - 实时,自动更新,R中的增量图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11365857/

相关文章:

r - 删除 R 中的多列时出错

r - 如何同时绘图到多个设备?

r - 使用 Base R 绘制数据子集的图表

c - C语言中的时间中断

linux - POSIX 实时信号能否实现软实时?

在指定的时间间隔运行 R 脚本

r - row.names() 和 attributes$row.names 有什么区别?

r - 使用 dplyr 中的 group_by 函数来操作 data.frame 对象集

r - ggplot2:来自 alpha 的颜色不一致

Qt 研究/学术/期刊论文/文章