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.
How can we create a gantt chart using ggplot showing the timeline of the construction of all buildings?
library(tidyverse)
library(lubridate)
tbl <- tibble(
buildings = c("A", "B", "C"),
start = ymd(c("2017-12-01", "2018-02-01", "2018-05-01")),
foundation = ymd(c("2018-01-01", "2018-04-01", "2018-06-01")),
structure = ymd(c("2018-02-09", "2018-05-01", "2018-07-01")),
interior = ymd(c("2018-05-01", "2018-06-01", "2018-07-24"))
)
Below is a simple example to create a Gantt chart taken from here. The above question will require some manipulation of data. We may have to create tasks such as - start_to_foundation
library(reshape2)
library(ggplot2)
tasks <- c("Review literature", "Mung data", "Stats analysis", "Write Report")
dfr <- data.frame(
name = factor(tasks, levels = tasks),
start.date = as.Date(c("2010-08-24", "2010-10-01", "2010-11-01", "2011-02-14")),
end.date = as.Date(c("2010-10-31", "2010-12-14", "2011-02-28", "2011-04-30")),
is.critical = c(TRUE, FALSE, FALSE, TRUE)
)
mdfr <- melt(dfr, measure.vars = c("start.date", "end.date"))
ggplot(mdfr, aes(value, name, colour = is.critical)) +
geom_line(size = 6) +
xlab(NULL) +
ylab(NULL)