【问题标题】:How to plot Time Interval only on x axis without date?如何仅在没有日期的 x 轴上绘制时间间隔?
【发布时间】:2016-03-23 07:55:38
【问题描述】:

我正在使用 R-3.2.4。 我一直在尝试仅在 x 轴上绘制数据,在 y 轴上绘制一些值,但每次它都会在 x 轴上显示一些日期以及时间,但是我只需要在 x 轴上显示时间间隔。

这是我正在使用的代码:

data_plot<-        read.csv("C:/.../Data_pract.csv",header=TRUE,stringsAsFactors=F)
data_plot$Time<-as.POSIXct(strptime(data_plot$Time, format="%H:%M"))
mydata<-ggplot(data_plot,aes(x=Time,y=January))+geom_line()
mydata

这是我正在使用的示例数据:

    Time January
    0:00    20
    0:15    30
    0:30    45
    0:45    40
    1:00    28
    1:15    15

我附上了我正在寻找的图表图像。

提前致谢。enter image description here

【问题讨论】:

标签: r ggplot2


【解决方案1】:

您可以使用函数 scale_x_datetime

将 ggplot 中的比例更改为日期时间
mydata<-ggplot(data_plot,aes(x=Time,y=January)) + geom_line() +
      scale_x_datetime(date_breaks = "1 hour",
                       date_labels = "%I:%M %p")

【讨论】:

  • 非常感谢罗伯特·普兰特。有效。它显示的时间格式是 24 小时制,有没有使用 12 小时制的选项?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-24
  • 1970-01-01
  • 1970-01-01
  • 2016-07-29
  • 1970-01-01
  • 2014-06-02
  • 1970-01-01
相关资源
最近更新 更多