【发布时间】:2018-01-03 07:44:48
【问题描述】:
使用如下数据框
data = data.frame(
name=rep(c('Toyota', "Honda", "Nissan") ,each=4)
,date=c(rep(seq(as.Date("2016/1/1"), by = "month", length.out = 4),2),rep(seq(as.Date("2017/1/1"), by = "month", length.out = 4),1)),
sales=sample(10:20, 12, replace=T)
)
我想绘制如下的销售折线图;
library(ggplot2)
ggplot(data, aes(x=date, y=sales)) + geom_line(aes(color=name))
这给了我 x 轴标签 2016-01 ... 2017-01 等等。
我需要将 x 轴标签设为 Jan-2016、Feb-2016 等。
【问题讨论】:
-
尝试添加类似
+ scale_x_date(date_breaks = "1 month", date_labels = "%b-%Y")的内容?