gpt4 book ai didi

r - scale_datetime 移动 x 轴

转载 作者:行者123 更新时间:2023-12-05 04:13:03 24 4
gpt4 key购买 nike

<分区>

我正在尝试使用 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"))

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com