【发布时间】:2021-05-28 09:31:44
【问题描述】:
基本上是这里描述的问题Plotting an xts object using ggplot2
但是我不能适应它来绘制两个系列,代码如下:
dates <- c("2014-10-01", "2014-11-01", "2014-12-01", "2015-01-01", "2015-02-01")
values1 <- as.numeric(c(1,2,3,4,5))
values2 <- as.numeric(c(10,9,8,7,6))
new_df <- data_frame(dates, values1, values2)
new_df$dates <- as.Date(dates)
new_df <- as.xts(new_df[, -1], order.by = new_df$dates)
现在我使用 ggplot:
ggplot(new_df, aes(x = Index, y = c(values1, values2)))
+ geom_point()
但我收到以下错误:
错误:美学长度必须为 1 或与数据相同 (5): y 运行
rlang::last_error()以查看错误发生的位置。
这个对象的两个系列可以放在同一个图上吗?
【问题讨论】: