gpt4 book ai didi

r - scale_x_datetime 产生错误?

转载 作者:行者123 更新时间:2023-12-04 10:34:41 28 4
gpt4 key购买 nike

我正在尝试使用 scale_x_datetime 来优化我的 x 轴。我从 ggplot2 website 阅读了文档,但此站点中的示例会生成与我遇到的错误相同的错误:

> library(ggplot2)
> start <- ISOdate(2001, 1, 1, tz = "")
> df <- data.frame(
+ day30 = start + round(runif(100, max = 30 * 86400)),
+ day7 = start + round(runif(100, max = 7 * 86400)),
+ day = start + round(runif(100, max = 86400)),
+ hour10 = start + round(runif(100, max = 10 * 3600)),
+ hour5 = start + round(runif(100, max = 5 * 3600)),
+ hour = start + round(runif(100, max = 3600)),
+ min10 = start + round(runif(100, max = 10 * 60)),
+ min5 = start + round(runif(100, max = 5 * 60)),
+ min = start + round(runif(100, max = 60)),
+ sec10 = start + round(runif(100, max = 10)),
+ y = runif(100)
+ )
>
> last_plot() + scale_x_datetime(major = "2 weeks", minor = "1 week")
Error in continuous_scale(aesthetics, "datetime", identity, breaks = breaks, :
unused argument(s) (major = "2 weeks", minor = "1 week")
>

那么是文档过时了还是这里有什么问题?

最佳答案

您使用的文档已过时,它适用于 v0.9.0 之前的版本。找到正确的here .您的示例现在应如下所示:

library(ggplot2)
library(scales) # for date_breaks()
start <- ISOdate(2001, 1, 1, tz = "")
df <- data.frame(
day30 = start + round(runif(100, max = 30 * 86400)),
day7 = start + round(runif(100, max = 7 * 86400)),
day = start + round(runif(100, max = 86400)),
hour10 = start + round(runif(100, max = 10 * 3600)),
hour5 = start + round(runif(100, max = 5 * 3600)),
hour = start + round(runif(100, max = 3600)),
min10 = start + round(runif(100, max = 10 * 60)),
min5 = start + round(runif(100, max = 5 * 60)),
min = start + round(runif(100, max = 60)),
sec10 = start + round(runif(100, max = 10)),
y = runif(100) )

qplot(sec10, y, data = df)
last_plot() + scale_x_datetime(breaks = date_breaks("2 weeks"),
minor_breaks = date_breaks("1 week"))

关于r - scale_x_datetime 产生错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12002317/

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