Search code examples
raxis-labelsdatetime-conversion

Time to axislabel in HH:MM:SS format from seconds in R


I'm new to R and programming in general. I have data with time in format "HH:MM:SS". For plotting purposes I converted it to seconds.

My problem now is how to convert the seconds in axis (x-axis in this case) labels back to this format in a such way that I can choose whether I want one second intervals, one minute intervals or one hour intervals or pretty much any user defined interval. Mostly 1, 15 or 30 seconds/minutes or 1,2 hours or a combination of these such as one minute and 30 seconds and also give these axis labels appropriate positions on the axis.

Open to any kinds of suggestions.


Solution

  • Use lubridate package

    library(lubridate)
    t<-seconds_to_period(5000)
    parse_date_time(t,"HMS")