Visualizing a staffing schedules in R

2019-06-07 14:53发布

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?

3条回答
等我变得足够好
2楼-- · 2019-06-07 15:30

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.

查看更多
The star\"
3楼-- · 2019-06-07 15:32

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

查看更多
ら.Afraid
4楼-- · 2019-06-07 15:42

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.

查看更多
登录 后发表回答