如何在 R/quantmod 的 chartSeries/candleChart 图中显示差距 [英] How to show gaps in R/quantmod's chartSeries/candleChart plots

查看:57
本文介绍了如何在 R/quantmod 的 chartSeries/candleChart 图中显示差距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 R 的优秀 quantmod 包中的绘图函数来显示财务数据中的差距".

I am trying to show "gaps" in financial data using the plotting functions in the excellent quantmod package for R.

通常,R 允许您使用 NA 值在图中显示间隙,如下所示:

Normally R allows you to show gaps in plots using NA values, as with:

x<-1:10
y<-2*x
y[4:7]<-NA
plot(x,y,type="l")

我想对 R/quantmod 的蜡烛图做类似的事情.但是,在绘图之前删除了包含 NA 的数据行(chartSeries 代码中有一个 na.omit 命令可以执行此操作),因此我看不到如何执行此操作.

I would like to do something similar with R/quantmod's candleChart plots. However, rows of data containing NA's are removed before plotting (there is a na.omit command in the chartSeries code that does this) so I cannot see how to do this.

一个例子是:

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

执行此操作的正确"方法是什么?我想我可以用我自己的这个函数版本(相同但没有 na.omit() 调用)覆盖 chartSeries,但这似乎非常激烈.

What is the "correct" way to do this? I guess I could overwrite chartSeries with my own version of this function (identical but without the na.omit() call), but that seems quite drastic.

有没有可能做这种事情的选项?我一直无法用谷歌搜索任何有用的东西...

Is there perhaps an option to do this kind of thing available? I have been unable to google anything useful...

谢谢,fttb

推荐答案

答案不是使用 chartSeries,而是使用更新的变体(技术上仍在开发中)chart_Series.注意下划线.

The answer is not to use chartSeries, but rather the newer variant (still in development technically) chart_Series. Note the underscore.

chart_Series(val2)

如果您正在寻找有关 quantmod 和在金融中使用 R 的更多详细信息,我们将于本月底在芝加哥举办一次大型会议.可在此处找到更多信息:R/Finance 2011

If you're looking for more details on quantmod and using R in finance, we are hosting a large conference in Chicago at the end of this month. More info can be found here: R/Finance 2011

希望能帮到你,希望在芝加哥见到你!!

Hope that helps, and hope to see you in Chicago!!

这篇关于如何在 R/quantmod 的 chartSeries/candleChart 图中显示差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆