3

I'm looking to create a timeline plot with a number of different actors that can perform different actions, and sometimes have more than one action at the same time. As an illustration, see this mockup:

Illustration of desired layout

The example illustrates that both P1 and P2 perform Activity 1 from 0:00 to 5:00. P1 then has the choice between Activities 2 and 3 between 5:00 and 17:00, while P2 has three choices, some of which also change over time.

How can I create plots like this using any arbitrary open source tool for plotting data, ideally GNUPlot (but R or matplotlib would also be fine)?

I've seen a number of similar questions (1, 2, 3, 4, 5, 6), but none of them adresses the question of concurrent actions by the same actor.

Context: The system will be used to visualize potential actions by whole groups of people. So, to give a bad example, if one group is "Students", then they may all sleep from 0:00 to 05:00, and then either work at home or work at the university until 17:00. Afterwards, they will all go back to sleep. This is not intended to be used as a Gantt chart for company planning, but to illustrate the different actions certain groups of the population may take at any time.

Community
  • 1
  • 1
malexmave
  • 1,283
  • 2
  • 17
  • 37
  • 2
    See http://stackoverflow.com/questions/3550341/gantt-charts-with-r . Also timeline and timelines packages. – G. Grothendieck Feb 03 '17 at 13:24
  • 1
    @G.Grothendieck thanks! I'm currently looking into it and the main issue I have with it is the display style of Gantt charts where new events proceed ever downwards, which would take up too much space for a 7-day interval I want to plot. timevis + groups may work, though. I'll look into it. Feel free to turn this into an answer so I can accept it once I validated that it indeed solves my problem :) – malexmave Feb 03 '17 at 13:32

1 Answers1

0

In case this still might be of interest, here is a suggestion using gnuplot.

Column 1 contains the person. Column 2 contains the number of splits before the . and the index after the . (this could also be split into two columns). Column 3 is the activity which is used for the color and in column 4 and 5 the start and end time, respecively.

This can certainly be improved, but may serve as starting point for further optimization or adaption.

Code: (tested with gnuplot 5.2.8)

### split time chart
reset session

$Data <<EOD
P1  3.2  A1  2021-01-05_00:00  2021-01-05_05:00
P1  2.1  A2  2021-01-05_05:00  2021-01-05_17:00
P1  2.2  A3  2021-01-05_05:00  2021-01-05_17:00
P1  3.2  A1  2021-01-05_17:00  2021-01-06_00:00
P2  3.2  A1  2021-01-05_00:00  2021-01-05_05:00
P2  3.1  A2  2021-01-05_05:00  2021-01-05_13:00
P2  3.1  A3  2021-01-05_13:00  2021-01-05_17:00
P2  3.2  A4  2021-01-05_05:00  2021-01-05_13:00
P2  3.2  A5  2021-01-05_13:00  2021-01-05_17:00
P2  3.3  A6  2021-01-05_05:00  2021-01-05_17:00
P2  3.2  A1  2021-01-05_17:00  2021-01-06_00:00
EOD

myTimeFmt = "%Y-%m-%d_%H:%M"
myActivity(col) = int(strcol(col)[2:])
myPerson(col) = int(strcol(col)[2:])
BoxHeight = 0.6
SubBoxCount(colBoxes) = int(strcol(colBoxes)[1:strstrt(strcol(colBoxes),'.')-1])
SubBoxIndex(colBoxes) = int(strcol(colBoxes)[strstrt(strcol(colBoxes),'.')+1:] -1)
SubBoxHeight(colBoxes) = BoxHeight/SubBoxCount(colBoxes)
BoxWidth(colStart,colEnd) = (timecolumn(colEnd,myTimeFmt)-timecolumn(colStart,myTimeFmt))/2.
BoxPosX(colStart,colEnd) = (timecolumn(colStart,myTimeFmt)+timecolumn(colEnd,myTimeFmt))/2.
BoxPosY(colPerson,colBoxes) = myPerson(colPerson) - 0.5 + (1.-BoxHeight)/2 + \
            SubBoxHeight(colBoxes)*(SubBoxIndex(colBoxes) + 0.5)

set format x "%H:%M" timedate
set grid xtics
set yrange [:] reverse
set offsets 0.25, 0.25, 0.25, 0.25
set ytics 1
set style fill transparent solid 0.5
set key out

plot $Data u (BoxPosX(4,5)):(BoxPosY(1,2)):(BoxWidth(4,5)):(SubBoxHeight(2)/2.):(myActivity(3)) w boxxy lc var notitle, \
     '' u (NaN):(myPerson(1)):ytic(1) notitle, \
     for [i=1:6] '' u (NaN):(0):(0):(0):(i) w boxxy lc var ti sprintf("A%d",i)
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72