title: Gantt chart to show timeline of construction process of buildings
body: <p>Below is a table containing the timeline of the construction of three buildings. The timelines include the start date, completion of each process - foundation, structure, and interior.</p>
  <p>How can we create a <a href="https://stackoverflow.com/questions/3550341/gantt-charts-with-r">gantt chart</a> using ggplot showing the timeline of the construction of all buildings?</p>
  <pre><code>library(tidyverse)
  library(lubridate)
  
  
  tbl &lt;- tibble(
    buildings = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;),
    start = ymd(c(&quot;2017-12-01&quot;, &quot;2018-02-01&quot;, &quot;2018-05-01&quot;)),
    foundation = ymd(c(&quot;2018-01-01&quot;, &quot;2018-04-01&quot;, &quot;2018-06-01&quot;)),
    structure = ymd(c(&quot;2018-02-09&quot;, &quot;2018-05-01&quot;, &quot;2018-07-01&quot;)),
    interior = ymd(c(&quot;2018-05-01&quot;, &quot;2018-06-01&quot;, &quot;2018-07-24&quot;))
  )
  </code></pre>
  <p>Below is a simple example to create a Gantt chart taken from <a href="https://stackoverflow.com/questions/3550341/gantt-charts-with-r">here</a>. The above question will require some manipulation of data. We may have to create tasks such as - <code>start_to_foundation</code></p>
  <pre><code>library(reshape2)
  library(ggplot2)
  
  tasks &lt;- c(&quot;Review literature&quot;, &quot;Mung data&quot;, &quot;Stats analysis&quot;, &quot;Write Report&quot;)
  dfr &lt;- data.frame(
    name        = factor(tasks, levels = tasks),
    start.date  = as.Date(c(&quot;2010-08-24&quot;, &quot;2010-10-01&quot;, &quot;2010-11-01&quot;, &quot;2011-02-14&quot;)),
    end.date    = as.Date(c(&quot;2010-10-31&quot;, &quot;2010-12-14&quot;, &quot;2011-02-28&quot;, &quot;2011-04-30&quot;)),
    is.critical = c(TRUE, FALSE, FALSE, TRUE)
  )
  mdfr &lt;- melt(dfr, measure.vars = c(&quot;start.date&quot;, &quot;end.date&quot;))
  
  ggplot(mdfr, aes(value, name, colour = is.critical)) + 
    geom_line(size = 6) +
    xlab(NULL) + 
    ylab(NULL)
  
  </code></pre>