r - 使用 ggplot2 绘制 xts 对象

标签 r ggplot2 xts

我想使用 ggplot2 绘制 xts 对象,但出现错误。这是我在做什么:

dates <- c("2014-10-01", "2014-11-01", "2014-12-01", "2015-01-01", "2015-02-01")
value <- as.numeric(c(3, 4, 5, 6, 5))
new_df <- data_frame(dates, value)
new_df$dates <- as.Date(dates)
new_df <- as.xts(new_df[,-1], order.by = new_df$dates)

现在我尝试使用 ggplot2 绘制它:
ggplot(new_df, aes(x = index, y = value)) + geom_point()

我收到以下错误:

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 0, 5



我不太确定我做错了什么。

最佳答案

将小写“索引”更改为大写“索引”

ggplot(new_df, aes(x = Index, y = value)) + geom_point()

关于r - 使用 ggplot2 绘制 xts 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43345388/

相关文章:

r - dplyr:对不同的组应用不同的功能

jquery - 在 Shiny App 中显示包含 DataTables 的 HTML 页面

r - 防止带有许多条形的 geom_bar 中的间距/条形宽度不一致

r - ggplot : placing facet strips above axis title

r summarise_if 有多个条件

r - 使用ggplot2仅绘制时间

r - ggplot2:按月和周绘制时间序列数据

r - 将函数应用于 xts 对象

r - 从不规则时间序列创建规则的15分钟时间序列

r - R中每小时分割时间序列数据