我试图使用优秀的 R Quantmod 包中的绘图函数来显示财务数据中的“差距”。
通常,R 允许您使用 NA 值显示图中的间隙,如下所示:
x<-1:10
y<-2*x
y[4:7]<-NA
plot(x,y,type="l")
我想用 R/quantmod 的 CandleChart 图做类似的事情。但是,包含 NA 的数据行在绘图之前被删除(chartSeries 代码中有一个 na.omit 命令可以执行此操作),因此我不知道如何执行此操作。
一个例子是:
require(quantmod)
#Make some pretend data
x<-0:30
y<-100+20*sin(x)
y.open<-y[-length(y)]
y.close<-y[-1]
val<-as.xts(cbind(y.open,y.open+5,y.close-5,y.close,1000),order.by=as.POSIXct(paste("2011-01-",x[-1],sep='')))
colnames(val)<-c("Open","High","Low","Close","Volume")
#Plot this pretend data
candleChart(val,theme="white")
#Now try and make a "gap" in the middle of the data and plot it
val2<-val
val2[5:20,]<-NA
candleChart(val2,theme="white")
执行此操作的“正确”方法是什么?我想我可以用我自己的这个函数版本覆盖 ChartSeries(相同但没有 na.omit() 调用),但这看起来相当激烈。
也许有一个选项可以做这种事情吗?我无法用谷歌搜索任何有用的东西......
谢谢,
fttb