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?

ST3
  • 8,826
  • 3
  • 68
  • 92
  • 2
    Post a dataset to work with. This site is not called "make-me-an-instant-tutorial.com". – IRTFM Oct 09 '13 at 19:26
  • 4
    Hmm. Search Stack Overflow for `[r] gantt` and see what that gets you. [This question](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) may be relevant, for example, but there are many more. If none suit, read [the canonical post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) 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. – SlowLearner Oct 09 '13 at 19:44
  • 1
    Hi and Welcome to stackoverflow! As you are new on SO, and to avoid faux pas, please read [about Stackoverflow](http://stackoverflow.com/about), [what to ask](http://stackoverflow.com/help/on-topic), and [how to ask](http://meta.stackoverflow.com/help/how-to-ask). – Henrik Oct 09 '13 at 20:45
  • Did you find any of the answers helpful? – Bryan Hanson Oct 10 '13 at 16:21

3 Answers3

3

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

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
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.

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
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.

AndrewMinCH
  • 710
  • 5
  • 8