2
我想繪製一個時間序列,它具有使用ggplot2的類「POSIXct」的x軸,該ggplot2正在工作到一個點。scale_datetime移動x軸
當我嘗試使用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"))