1

First time poster here, so please forgive any faux pas on my part.

I have a set of data which consists of essentially 3 fields:

1)Position 2)Start_of_shift (datetime object) 3)End_of_Shift (datetime object)

From the datetime object I can extract date, day of week, & time. The schedules are 24/7 and do not conform to any standard 3 shift etc. rotation, they are fairly specific to a site. (I am using the lubridate package)

I would like to visualize Time of day vs. Day of Week to show numbers of staff, so that I can see heavy concentrations of staff and where I am light at specific days and times.

I am unsure on how to approach this problem as I am relatively new to R and I have found the various date time packages & base utilities confusing and often conflicting with each other. While I find plenty of examples of time series plotting, I have found next to nothing on how to plot if you have a start and end time in separate fields and want to show areas of overlap

I was thinking of using ggplot2 with geom_tile to plot this out, with a smoother, but wanted to know if there were any good examples out there that do something similar or if anyone has any idea on how I should transform my data to best achieve my end objective. I wanted to keep the time continuous but as a last resort I will discretize it into 15 minute chunks if necessary, but didn't know if there were other options?

Any thoughts?

4
  • 2
    Post a dataset to work with. This site is not called "make-me-an-instant-tutorial.com".
    – IRTFM
    Oct 9, 2013 at 19:26
  • 4
    Hmm. Search Stack Overflow for [r] gantt and see what that gets you. This question may be relevant, for example, but there are many more. If none suit, read the canonical post on making a minimal reproducible example (the vaunted MRE) and come back here to edit your question. For what it's worth, I use plain data frames to store my time series data, with the date in yyyy-mm-dd format in the first column. Oct 9, 2013 at 19:44
  • 1
    Hi and Welcome to stackoverflow! As you are new on SO, and to avoid faux pas, please read about Stackoverflow, what to ask, and how to ask.
    – Henrik
    Oct 9, 2013 at 20:45
  • Did you find any of the answers helpful? Oct 10, 2013 at 16:21

3 Answers 3

3

You might consider using a gannt chart, the gannt.chart function in the plotrix package is one option for creating them.

3

Maybe the timeline package is what you need. I've found it very good for planning projects. It's on CRAN, but you can see a quick example at it's Github home here.

0

To work out how many people are present (or should be if it's a future event) you need to think of your staffing as a stock / flow.

First step would be to use the melt function in package reshape2 to get all the dates in one column and the event (starting / finishing) in another.

From this you can create a running total of how many people will be in at any time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.