我知道使用scale_x_date(date_labels="%b"...)
会创建包含每月前三个字母的刻度标签。有没有办法只包括每个月的第一个字母?因此,而不是"Jan Feb March..."
,标签将是"J F M..."
。使用每月的第一个字母创建ggplot2 x轴月标签
下面是一个例子:月份标签重叠,所以我希望能够将标签更改为第一个字母。
library(lubridate)
library(ggplot2)
set.seed(2)
df = data.frame(Date=seq(as.Date("2010-01-01"),as.Date("2015-12-31p
"), by="1 day"))
df$value = cumsum(rnorm(nrow(df)))
p = ggplot(df, aes(Date, value)) +
geom_vline(xintercept=as.numeric(df$Date[yday(df$Date)==1]), colour="grey60") +
geom_line() +
scale_x_continuous(labels = year_labels <- rep(c('J','F','M','A','M','J','J','A','S','O','N','D'),5)) +
theme_bw() +
theme(panel.grid.minor.x = element_blank()) +
labs(x="")
p
我试图改变线scale_x_date(date_labels="%b", date_breaks="month", expand=c(0,0))
到scale_x_continuous(labels = year_labels <- rep(c('J','F','M','A','M','J','J','A','S','O','N','D'),5))
但由此产生下面的错误
错误as.Date.numeric(值):“原点'必须提供
可以请你提供一个可重复的例子 –
你的例子是不可复制的 –
我只是跳过'geom_vline(xintercept = as.numeric(df $ Date [yday(df $ Date)== 1]),color =“ grey60“)',我认为只是*装饰的一部分*,并且它工作正常 – Marco