实时,自动更新,R中的增量图 [英] Real time, auto updating, incremental plot in R
本文介绍了实时,自动更新,R中的增量图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个动态图,有点像自动更新,增量式的,可能是实时的. 我想完成这样的事情 http://www.youtube.com/watch?v=s7qMxpDUS3c
I'm trying to make a dynamic plot, sort of like auto updating, incremental, possibly real time. I want to accomplish something like this http://www.youtube.com/watch?v=s7qMxpDUS3c
这是我到目前为止所做的.假设您在一个名为temp的data.frame中有一个时间序列.第一列是时间,第二列是值所在的位置.
This is what I have done so far. Suppose you have a time series in a data.frame called temp. First column is the time and the second column is where the values are.
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个单位的长时间序列,相反,我只得到了一点更新.
This does plot incrementally but I don't get the 100 units long time series instead i get just one point updating.
推荐答案
您要这样做吗?
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中的增量图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文