【发布时间】:2016-07-24 00:30:44
【问题描述】:
我想在我的图表中加入一些小刹车,以便在每个月初打印完整的日期,并且在 x 轴上只用一个勾号来标记日期。 我现在所拥有的不会检索错误,但输出不是我想要的,因为这些天没有刻度。
library(ggplot2)
df <- data.frame(date=as.Date(1:60,origin = "1970-01-01"),value=rnorm(60,4,3))
str(df)
ggplot()+
geom_line(data=df, aes(x=date, y=value))+
scale_x_date(date_breaks = 'month', date_minor_breaks = 'day')
会话:
other attached packages:
[1] scales_0.4.0 cowplot_0.6.2 ggplot2_2.1.0 dplyr_0.5.0 zoo_1.7-13
这个问题已经在Formatting dates with scale_x_date in ggplot2 中讨论过,但我想知道在此期间是否发生了一些变化,因为如果我按照建议的代码进行操作
scale_x_date(breaks = "1 month", minor_breaks = "1 week", labels=date_format("%B"))
我实际上得到了一个错误
> ggplot()+
+ geom_line(data=df, aes(x=date, y=value))+
+ scale_x_date(breaks = "1 month", minor_breaks = "1 week", labels=date_format("%B"))
Error in strsplit(unitspec, " ") : non-character argument
【问题讨论】: