Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中建立图表(绘图):时间间隔内的中间价格_R - Fatal编程技术网

在R中建立图表(绘图):时间间隔内的中间价格

在R中建立图表(绘图):时间间隔内的中间价格,r,R,我有一些拍卖的价格和结束日期的数据框。我想检查何时显示,例如,根据一天中的时间,具有最低和最高价格(也是中值)的销售额 更准确地说,我有数据帧mtest: > str(mtest) 'data.frame': 9144 obs. of 2 variables: $ Price : num 178 188 228 305 202 ... $ EndDateTime: POSIXct, format: "2015-05-25 05:00:59" "2015-05-23 00:

我有一些拍卖的价格和结束日期的数据框。我想检查何时显示,例如,根据一天中的时间,具有最低和最高价格(也是中值)的销售额

更准确地说,我有数据帧
mtest

> str(mtest)
'data.frame':   9144 obs. of  2 variables:
$ Price      : num  178 188 228 305 202 ...
$ EndDateTime: POSIXct, format: "2015-05-25 05:00:59" "2015-05-23 00:06:01"  ...
我想建立一个图表(绘图),在X轴上有30分钟的时间(00:00-00:30,00:31-01:00等),在Y轴上有中位数(最高、最低价格)。
另一个想法是为每个时间间隔绘制一个简单的直方图,如
hist(mtest$Price,breaks=10,col=“red”)

我怎样才能以最好的方式做到这一点?

试试这个:

cutt=seq(from=min(mtest$EndDateTime),to=max(mtest$EndDateTime), by=30*60)
if (max(mtest$EndDateTime)>max(cutt))cutt[length(cutt)+1]=max(cutt)+30*60
mtest$tint=cut(mtest$EndDateTime,cutt)
stats=do.call(rbind,tapply(mtest[,"Price"],mtest[,"tint"],
                     function(p)c(min=min(p),median=median(p),max=max(p))))
bp=boxplot(mtest[,"Price"]~mtest[,"tint"],xaxt="n",
           col=1:length(levels(mtest$tint)))
axis(1,at=1:length(levels(mtest$tint)),labels=format.Date(levels(mtest$tint),"%Y-%m-%d %H:%M"),
     las=2,cex.axis=.5)
stats
还是威尔特阴谋

plot(NA,ylim=range(stats),xlim=c(1,lint),type="n",xaxt="n",xlab="",ylab="")
sapply(1:3,function(z)points(stats[,z]~c(1:lint),col=z))
axis(1,at=1:lint,labels=format.Date(levels(mtest$tint),"%Y-%m-%d %H:%M"),
     las=2,cex.axis=.5)
您将有如下内容: