将计时时间绘制为从原点开始的小时数 [英] plot chron times as hours from origin

查看:117
本文介绍了将计时时间绘制为从原点开始的小时数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组计时时间,这是两个时间点之间的差.这些值的范围从稍负到略大于1.Chron将这些值显示为几天的时间,因为某些值大于1.

I have a set of chron times that is the difference between two time points. These values range from slightly negative to slightly greater than 1. Chron displays these values as a fraction of days because some of the values are greater than 1.

当我在ggplot中绘制这些值时,我尝试使用scale_y_chron()正确注释y轴,但是scale_y_chron()似乎仅绘制24小时内的时间.从00:00起我有什么方法可以将轴注释为HH:MM吗?

When I plot these values in ggplot, I tried using scale_y_chron() to correctly annotate the y axis, however scale_y_chron() appears to only plot time within a 24 hour period. Is there any way that I can annotate the axis as HH:MM from 00:00?

# data:

time_to <- c(0.19305556,0.12083333,0.58402778,0.32986111,0.40486111,
             0.77083333,0.18263889,0.23472222,0.10138889,0.11666667,
             0.47222222,0.14166667,0.15694444,0.24166667,0.16666667,
             0.29166667,0.28194444,0.16875000,0.42777778,0.88750000,
             0.17916667,0.05763889,0.53263889,0.11666667,0.22916667,
             0.75069444,0.98680556,1.29930556,0.78263889,0.73611111,
             0.73958333,1.22708333,0.41319444,0.98402778,1.22500000,
             0.33194444,0.95972222,0.18333333,0.11458333,0.86805556)

# plot:

require(chron)
require(ggplot2)
qplot(y=time_to)

理想情况下,y轴应说明从00:00开始的总小时数,但如果时差大于24小时,则默认为天.

The y-axis should ideally state total hours from 00:00, but it defaults to days if the time difference is greater than 24 hours.

推荐答案

time_to仅仅是数字的向量,因此没有理由认为轴会用数字以外的其他东西标记.如果这些数字代表两个日期之间的时差,并且我们希望HH:MM格式,即使超过24小时也要使用自定义标签.利用这样的事实,即一天中的一天为1,因此一小时为1/24:

time_to is just a vector of numbers and so there is no reason to think the axes would be labelled by anything other than numbers. If those numbers represent the difference between two chron datetimes and we want HH:MM format even if greater than 24 hours use a custom label. Make use of the fact that in chron a day is 1 so one hour is 1/24:

library(ggplot2)

hrs <- seq(0, 30, 5)  # 0, 5, 10, ..., 30
qplot(y = time_to) + 
   scale_y_continuous(breaks = hrs/24, labels = sprintf("%02d:00", hrs))

这篇关于将计时时间绘制为从原点开始的小时数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆