将X轴从日期转换为ggplot2中的HRS
在48小时内,我有一个受体压力探针的记录。从Excel导入数据后,我获得了两个vars时间(class =“ posixct”和probe('numeric')。
'data.frame': 3647 obs. of 2 variables:
$ Date : POSIXct, format: "2020-01-15 17:34:02" "2020-01-15 17:34:42"...
$ probe: num 31.6 35.8 29.9 29.1 30.1...
我使用ggplot2和geom_line绘制vars,我得到了此图
x轴显示时间(总48 h) 但是,当我尝试使用以下方式格式化时间时:
library(hms)
data$time<-as_hms(data$Date)
我有一个凌乱的情节。我尝试了不同的方法将“数据$时间”转换为不同的量表,但我无法管理。 任何帮助将不胜感激
I have a recording during 48 h of a probe of pressure of a recipient. After importing data from Excel I get two vars Time (class= "POSIXct" and Probe ('numeric').
'data.frame': 3647 obs. of 2 variables:
$ Date : POSIXct, format: "2020-01-15 17:34:02" "2020-01-15 17:34:42"...
$ probe: num 31.6 35.8 29.9 29.1 30.1...
I plot both vars using ggplot2 and geom_line and I get this graph
The X axis shows time (total 48 h)
However, when I try to format time by using:
library(hms)
data$time<-as_hms(data$Date)
I got a messy plot. I have tried different methods to convert 'data$time' to a different scales but I cannot manage this.
Any help would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过
scale_x_datetime
来解决这一问题,通过创建breaks向量并使用date_labels
格式字符串标记。我创建了一个测试数据集,因为问题中没有。
在2022-05-28上由 reprex软件包(v2.0.1)
This is solved with
scale_x_datetime
by creating a breaks vector and labeling with adate_labels
format string.I have created a test data set, since there is none in the question.
Created on 2022-05-28 by the reprex package (v2.0.1)