【发布时间】:2020-11-24 11:46:51
【问题描述】:
在 R 上运行 date_function 时遇到问题。我尝试了几个不同的示例。重现步骤
示例 1
coord_x_date(xlim = c("2020-07-02", "2020-07-09"), ylim =
c(5,30))
+
scale_x_datetime(date_breaks = "2 hours")
Error: Invalid input: time_trans works with objects of class
POSIXct only
示例 2
coord_x_date(xlim = c("2020-07-02", "2020-07-09"), ylim = c(5,30)) +
scale_x_date(date_minor_breaks = "2 hours")
Error in cut.Date(date, time, right = TRUE, include.lowest = TRUE) :
invalid specification of 'breaks'
示例 3
coord_x_date(xlim = c("2020-07-02", "2020-07-09"), ylim = c(5,30)) +
+
scale_x_datetime(breaks = date_breaks("1 day"), minor_breaks =
date_breaks("2 hour"))
Error: Invalid input: time_trans works with objects of class
POSIXct only
scale_x_datetime(xlim =as.POSIXct(c("2020-07-02", "2020-07-09"))) 不起作用 知道我可能做错了什么吗?
【问题讨论】:
-
您正在使用字符串日期,它要求 POSIXct。错误信息很清楚。
-
scale_x_datetime(xlim =as.POSIXct( c("2020-07-02", "2020-07-09")))应该可以解决问题