【发布时间】:2016-12-04 02:00:57
【问题描述】:
我正在尝试使用 ggplot2 绘制一个 x 轴为“POSIXct”类的时间序列,它正在工作到一个点。
当我尝试使用 scale_x_datetime 操作 x 轴中断和标签时,它会在 x 轴上产生一个月的偏移。
谁能解释一下,并提供解决方案?
示例简化代码:
start <- as.POSIXct("2014/07/01 00:00:00")
end <- as.POSIXct("2014/10/01 23:30:00")
interval <- as.difftime("00:30:00")
df <- data.frame(t=seq(start, end, by="1 day"))
df$v <- sample(1:100, replace=TRUE, nrow(df))
p <- ggplot(data=df, aes(x=t)) +
geom_line(aes(y=v))
p2 <- p + scale_x_datetime(breaks=date_breaks("1 month"), labels=date_format("%b-%y"))
【问题讨论】: