我想使用 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/