# Plotting the gap between two times

I have a (large) dataset where I know, for each observation, the departure and the arrival time of a worker (between 0 and 24, in decimal) :

ID      Departure_time    Arrival_time
0001    07.00             08.25
0002    07.55             08.20
0003    08.10             09.75
...     ...               ...


I can plot the density of the departure_time (or arrival_time) easily :

ggplot(df, aes(x=Departure_time)) + geom_density(adjust=.5)


I would like to plot the density of workers traveling for a given time (for each moment, the number of worker who are not at work (prior to arrival_time) but who have left home (after departure_time).

• Do you want to know the number of workers en route at a given point in time, or the typical duration of a worker's commute? – gung Jun 19 '13 at 14:17
• The number of workers at a given time! I could get the typical duration with a subtraction: mean(arrival_time-departure_time). – Sylvain Jun 19 '13 at 14:20
• A loop over workers and a counter wich is incremented if departure < time < arrival will give you the number of workers travelling at a given time... Then loop on times. – were_cat Jun 19 '13 at 15:07

#Make this as fine as you want it.