【发布时间】:2021-02-23 17:05:50
【问题描述】:
所以假设我有数据集:
date order_sum
2015-01-01 800
2016-08-19 900
2019-04-16 1200
2020-10-28 850
这是我的月转换:sales$month <- month(sales$date)
这是我在 x 轴上使用的最小值:min <- ymd("2020-11-01")
这是指定我的 df 的基本图:baseplot <- ggplot(sales, aes(month, order_sum))
我正在尝试制作该月的日期与 order_sum 总和的基本图表,并将 x 轴上的日期显示为 11-2020。
scale_x_date(limits = c(min, now), breaks = "1 month", labels = date_format("%m-%Y")) +
scale_y_continuous(labels = function(x) scales::dollar(x, suffix = 'M'), n.breaks = 3, expand = expansion(mult = c(0, 0.05))) +
labs(x = "Date", y = "Order Volume")
我在文本块上得到的错误是这样的:
as.Date.default(e) 中的错误:不知道如何将 'e' 转换为类“Date”
有人知道为什么吗?提前致谢!
【问题讨论】:
标签: r ggplot2 lubridate as.date