【问题标题】:Adding points to xts plot将点添加到 xts 图
【发布时间】:2011-09-05 04:49:00
【问题描述】:

我以为Adding Points, Legends and Text to plots using xts objects 会回答这个问题,但显然不是......

require(quantmod)
getSymbols("SAM")
big.red.dot <- zoo(85, as.Date("2011-05-05"))
plot(SAM['2011'])
points(  big.red.dot, col="red", pch=19, cex=5  )

这似乎是直接从教科书出来的。 ?plot.zoo 不包含任何带有 point() 的示例。

【问题讨论】:

  • @Joshua Ulrich 感谢您更正标题(并编写包!)。标题编辑的顺序清楚地表明,如果最后一个存在,我不明白plot.zooplot.xts 和“quantmod plot”之间的区别。你能给我指个参考吗?
  • @Lau Tzu:plot 是一个通用函数。 plot.zooplot.xts 只是 zoo 和 xts 类对象的方法。请参阅?plot.zoo?plot.xts 了解每个相应功能的说明。 quantmod 具有chartSeries 绘图功能。
  • @isomorphismes 我也应该看看Methods(plot) 以了解plot(通用的)是如何工作的。还有adv-r.had.co.nz/OO-essentials.html#s3

标签: r graphics xts zoo quantmod


【解决方案1】:

默认情况下,quantmod::getSymbols 创建的对象实际上属于 xts 类。这意味着您的 big.red.dot 应该是 xts 对象:

big.red.dot <- xts(85, as.Date("2011-05-05"))
plot(SAM['2011'])
points(  big.red.dot, col="red", pch=19, cex=5  )

【讨论】:

  • 谢谢!我对答案如此明显并不感到惊讶。
猜你喜欢
  • 2018-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-03
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多