【问题标题】:barplot for xts objectsxts 对象的条形图
【发布时间】:2012-03-06 22:26:21
【问题描述】:

我可以使用 barplot 来绘制 xts 对象吗?或者我可以使用任何类似的功能吗? quantmod 不是我要说的,因为它不够灵活且与其他 R 图形不兼容。

【问题讨论】:

  • 基本 R 图中的任何解决方案?

标签: r xts


【解决方案1】:

您可以提取索引和值 带有index 的 xts 或 zoo 对象 和coredata:这就足够了 以你想要的方式绘制它。

# Sample data
library(quantmod)
getSymbols("^GSPC")
x <- Vo( GSPC )

# Base graphics
plot( index(x), coredata(x), type="h" )

# ggplot2
d <- data.frame( time=index(x), volume=drop(coredata(x)) )
library(ggplot2)
ggplot(d, aes(time, volume)) + geom_bar(stat="identity")

【讨论】:

  • 非常感谢!这激发了我的灵感,只需稍微改变一下就可以在我的上下文中达到目的~~
  • 我收到这个错误..找不到函数“barplot.xts”..我错过了一些包吗?它一直有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-27
  • 2019-03-19
  • 2019-06-15
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多