Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7981615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:25:44+00:00 2026-06-04T10:25:44+00:00

I am measuring the duration of an event, and I would like to plot

  • 0

I am measuring the duration of an event, and I would like to plot the duration, and time the event takes place in each observation day.

My dataset is the following

> str(question.stack)
'data.frame':   398 obs. of  6 variables:
 $ id              : Factor w/ 1 level "AA11": 1 1 1 1 1 1 1 1 1 1 ...
 $ begin.recording : Factor w/ 1 level "8/15/2007": 1 1 1 1 1 1 1 1 1 1 ...
 $ begin.of.episode: Factor w/ 111 levels "1/1/2009","1/11/2009",..: 86 86 86 87 88 90 90 96 96 103 ...
 $ episode.day     : int  12 12 12 13 14 15 15 17 17 18 ...
 $ start.time      : Factor w/ 383 levels "0:06:01","0:17:12",..: 324 15 18 179 269 320 379 281 287 298 ...
 $ duration        : num  278 14 1324 18 428 ...

I would like in the x axis the episode.day. The y axis should go from 00:00 to 23:59:59 (start.time). For example, for the second entry of the dataset, i would like a black bar starting at (x=12,y=10:55:12) till (x=12, y=11:09:12) denoting a 14 minute episode duration on day 12. An episode can span between more than 1 days.

Is this possible with R? If possible please only baseR solutions

Something similar is Plot dates on the x axis and time on the y axis with ggplot2 but not exactly what I am looking.

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:25:46+00:00Added an answer on June 4, 2026 at 10:25 am

    Ok I finally found it.

    On the x axis I wanted to plot dates either as POSIXct or as number of day of recording (integer). On the y axis I wanted the time of day so that the graph would present a dark bar on each day (x-axis) and between the time (y-axis) that the episode take place.

    R can plot POSIX, but in my case the episode start and end time (for the y-axis) should be date-“less”

    I did this like this

    #Cleaning the Dataset
    qs<-question.stack
    qs$id<-as.character(qs$id)
    qs$begin.recording<-as.character(qs$begin.recording)
    qs$begin.of.episode<-as.character(qs$begin.of.episode)
    qs$start.time<-as.character(qs$start.time)
    qs$start<-as.character(paste(qs$begin.of.episode,qs$start.time))
    qs$duration<-round(qs$duration,0)
    
    #Convert time and dates to POSIXct
    qs$start<-as.POSIXct(qs$start,format="%m/%d/%Y %H:%M:%S",tz="UTC")
    qs$start<-round(qs$start,"mins")
    qs$end<-as.POSIXct(qs$start+qs$duration*60)
    qs$start<-as.POSIXct(qs$start)
    

    Now we have

    str(qs)
    'data.frame':   398 obs. of  8 variables:
     $ id              : chr  "AA11" "AA11" "AA11" "AA11" ...
     $ begin.recording : chr  "8/15/2007" "8/15/2007" "8/15/2007" "8/15/2007" ...
     $ begin.of.episode: chr  "8/27/2007" "8/27/2007" "8/27/2007" "8/28/2007" ...
     $ episode.day     : int  12 12 12 13 14 15 15 17 17 18 ...
     $ start.time      : chr  "6:15:12" "10:55:12" "11:15:12" "18:19:12" ...
     $ duration        : num  278 14 1324 18 428 ...
     $ start           : POSIXct, format: "2007-08-27 06:15:00" "2007-08-27 10:55:00" ...
     $ end             : POSIXct, format: "2007-08-27 10:53:00" "2007-08-27 11:09:00" ...
    

    The following makes a vector which includes all minutes that there was an episode. One can fine tune it by seconds or upscale it by hours

    tmp<-do.call(c, apply(qs, 1, function(x) seq(from=as.POSIXct(x[7]), to=as.POSIXct(x[8]),by="mins")))
    

    The following makes a data frame. The switch of the time of day from POSIX to (date-“less”) and then back to POSIX garantees that there will be the same date in all times of time.of.day. Perhaps one can also do it with the origin argument.

    ep <- data.frame(sqs=tmp, date=as.Date(tmp,"%Y-%m-%d"),time.of.day=as.POSIXct(as.character(format(tmp,"%H:%M")),format="%H:%M"))
    

    Plot

    plot(ep$date, ep$time.of.day,pch=".")
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if there is a simple way of measuring the
I have two scenarios of measuring metrics like computation time and parallel speedup (sequential_time/parallel_time).
I have following macro for measuring time in header file: #define TIMER_START(x) double ___timer__##x
For the profiler which I implement using JVMTI I would like to start measuring
i am measuring physical time between two events like this: #include <time.h> #include <sys/time.h>
I am measuring the duration of episodes (vector ep.dur in minutes) per day, for
What tools are best for measuring web-services performance? It would be nice to get
I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685 However, it does
I wanna measure the performance to my database by measuring the time taken to
I found an example of QueryPerformanceCounter, http://advancedcppwithexamples.blogspot.com/2009/08/measuring-elapsed-time-in-c-using_21.html The example measures a sleep of 100ms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.