文本未出现在 XTS 图中 [英] Text not appearing on XTS plot

查看:54
本文介绍了文本未出现在 XTS 图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 xts 在 R 中的时间序列数据图中添加一些文本.我已经制作了一个简单的问题示例.

I'm having trouble adding some text to an plot of time series data in R using xts. I've produced a simple example of the problem.

我的 text() 命令似乎什么都不做,而我可以在图中添加一个点.我试图通过尽可能使用默认值来保持代码简单

My text() command seems to do nothing, whereas I can add a points to the plot. I've tried to keep the code simple by using defaults where possible

require(quantmod)

# fetch the data and plot it using default options
getSymbols('MKS.L')
plot(MKS.L$MKS.L.Close)

# try to add text - doesn't appear
text(as.Date('2012-01-01'),y=500,"wobble", cex=4)

# add a point - this does appear
testPos <- xts(600, as.Date('2012-01-01'))
points( testPos, pch = 3, cex = 4, col = "red" )

感谢任何帮助 - 我对 R 还很陌生,我已经花了几个小时!

Any help appreciated - I'm pretty new to R and I've spent hours on this!

推荐答案

不是直接的答案,但是 xts 包自带的 plot.xts 函数不是全面发展.

Not a direct answer, but the plot.xts function that comes with the xts package is not fully developed.

最好使用 xtsExtra 包(它是作为 Google Summer of Code 项目编写的,目的是将其纳入 xts 包)

You're much better off using plot.zoo or plot.xts from the xtsExtra package (which was written as a Google Summer of Code project with the intention being to roll it into the xts package)

其中任何一个都可以:

plot(as.zoo(MKS.L$MKS.L.Close))
text(as.Date('2012-01-01'),y=500,"wobble", cex=4)

#install.packages("xtsExtra", repos="http://r-forge.r-project.org")
xtsExtra::plot.xts(MKS.L$MKS.L.Close)
text(as.Date('2012-01-01'),y=500,"wobble", cex=4)

这篇关于文本未出现在 XTS 图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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