【问题标题】:Date Function in RR中的日期函数
【发布时间】: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"))) 应该可以解决问题

标签: r date ggplot2


【解决方案1】:

你可以用coord_x_datetime对应scale_x_datetime

  coord_x_datetime(xlim = c(("2020-07-02", "2020-07-09"), ylim = c(5,30)) +
 scale_x_datetime(date_breaks = "1 hours")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 2021-04-25
    • 2017-09-06
    相关资源
    最近更新 更多