在早期版本的ggplot2中,我能够使用以下两个命令之一来格式化我的x轴日期:
要么
scale_x_date(breaks = "1 month", minor_breaks = "1 week", labels=(date_format="%B")) +
或者scale_x_date(major="months", minor="weeks", format="%B") +
生成"%B"格式,代表完整的月份名称。
很抱歉我已经无法区分哪个方法起作用了,因为它们都被注释掉了。
我不记得是什么时候,在Ubuntu 12.04升级之后更新了R或ggplot之后,这个方法对我不再起作用。现在,相同的数据会产生错误:
Error in scale_labels.continuous(scale) :
Breaks and labels are different lengths
使用第一个,并且
Error in continuous_scale(aesthetics, "date", identity, breaks = breaks, :
unused argument(s) (major = "months", minor = "weeks", format = "%B")
加入第二个。
如果我删除 labels= 参数,并应用
scale_x_date(breaks = "1 month", minor_breaks = "1 week") +
每个月的第一天会生成“YYYY-MM-DD”格式的日期。
查看函数?scale_x_date的帮助后,我也尝试了以下操作:
scale_x_date(breaks = "1 month", minor_breaks = "1 week", labels=date_format("%B")) +
但是这会产生以下错误:
Error in structure(list(call = match.call(), aesthetics = aesthetics, :
could not find function "date_format"
如何在我的x轴上实现月份名称的"%B"格式?(如果您对产生这些错误消息的机制有任何其他见解,我也会感激不尽。)