Text not appearing on XTS plot

孤街醉人 提交于 2019-12-22 10:24:34

问题


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.

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

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


回答1:


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

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)

Either of these will work:

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)


来源:https://stackoverflow.com/questions/18313073/text-not-appearing-on-xts-plot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!