Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Pretty similar to @John's approach, but since I did it, I will post it :)</p> <p>Here's a generic function to plot a gantt (no dependencies):</p> <pre><code>plotGantt &lt;- function(data, res.col='resources', start.col='start', end.col='end', res.colors=rainbow(30)) { #slightly enlarge Y axis margin to make space for labels op &lt;- par('mar') par(mar = op + c(0,1.2,0,0)) minval &lt;- min(data[,start.col],na.rm=T) maxval &lt;- max(data[,end.col],na.rm=T) res.colors &lt;- rev(res.colors) resources &lt;- sort(unique(data[,res.col]),decreasing=T) plot(c(minval,maxval), c(0.5,length(resources)+0.5), type='n', xlab='Duration',ylab=NA,yaxt='n' ) axis(side=2,at=1:length(resources),labels=resources,las=1) for(i in 1:length(resources)) { yTop &lt;- i+0.1 yBottom &lt;- i-0.1 subset &lt;- data[data[,res.col] == resources[i],] for(r in 1:nrow(subset)) { color &lt;- res.colors[((i-1)%%length(res.colors))+1] start &lt;- subset[r,start.col] end &lt;- subset[r,end.col] rect(start,yBottom,end,yTop,col=color) } } par(mar=op) # reset the plotting margins } </code></pre> <p>Usage example:</p> <pre><code>data &lt;- read.table(text= '"person","n","start","end" "sam",6,0,6 "greg",5,6,11 "teacher",4,11,15 "sam",4,15,19 "greg",5,19,24 "sally",5,24,29 "greg",4,29,33 "sam",3,33,36 "sally",5,36,41 "researcher",6,41,47 "greg",6,47,53',sep=',',header=T) plotGantt(data, res.col='person',start.col='start',end.col='end', res.colors=c('green','blue','brown','red','yellow')) </code></pre> <p>Result:</p> <p><img src="https://i.stack.imgur.com/MGEjF.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload