Each time I have tried to figure out how to manage Gantt chart presentation
in some spreadsheet software, I faced with many problems. The
major problem was to make breaks in bars on the chart for task that
repeats. Fortunately, Marcel Ramos proposed a quick solution in R using 'plotrix' package. In this example I will present how I've created Gantt chart for tasks that are planned on project dealing with wild plants collection and introduction into Botanical garden. First, I've created 'garden.csv' data file in which I've scheduled start and end date for each operation. Some of them repeats in different segments of the year. The file looks something like this:
task | start | end | axis | label |
---|---|---|---|---|
Collecting | 2017/03/01 | 2017/03/05 | 2017/01/01 | Jan |
Collecting | 2017/04/01 | 2017/04/05 | 2017/02/01 | Feb |
Collecting | 2017/05/01 | 2017/05/05 | 2017/03/01 | Mar |
Collecting | 2017/06/01 | 2017/06/05 | 2017/04/01 | Apr |
Collecting | 2017/07/01 | 2017/07/05 | 2017/05/01 | May |
Collecting | 2017/08/01 | 2017/08/05 | 2017/06/01 | Jun |
Collecting | 2017/09/01 | 2017/09/05 | 2017/07/01 | Jul |
Pot care | 2017/05/06 | 2017/09/06 | 2017/08/01 | Aug |
Planting | 2017/03/06 | 2017/03/11 | 2017/09/01 | Sep |
Planting | 2017/04/06 | 2017/04/11 | 2017/10/01 | Oct |
Planting | 2017/09/06 | 2017/09/11 | 2017/11/01 | Nov |
Photo-shoot | 2017/05/01 | 2017/08/01 | 2017/12/01 | Dec |
Making herbar | 2017/05/01 | 2017/07/01 | ||
Data base | 2017/08/01 | 2017/12/01 | ||
Web-site | 2017/01/01 | 2017/03/01 | ||
Web-site | 2017/10/02 | 2017/12/31 |
At this point you just have to be sure that the date format in your file is 'yyyy/mm/dd'. Here is the code for producing the Gantt chart out of these data:
library(plotrix)
df <- read.csv("./data/garden.csv", header = TRUE)
Ymd.format<-"%Y/%m/%d"
gantt.info<-list(labels= df$task,
starts= as.POSIXct(strptime(df$start, format=Ymd.format)),
ends= as.POSIXct(strptime(df$end, format=Ymd.format)))
vgridpos<-as.POSIXct(strptime(df$axis,format=Ymd.format))
vgridlab<- df$label
tiff(filename = "./data/garden.tiff",
width = 2000, height = 1000,
units = "px", pointsize = 12,
compression = c("lzw"),
bg = "white", res = 150,
type = c("cairo"))
gantt.chart(gantt.info,main="", border.col="black",
vgridpos=vgridpos,vgridlab=vgridlab, hgrid=TRUE,
taskcolors=c("red", "blue", "green", "yellow", "magenta", "purple", "cyan"))
dev.off()
Finally, this is how Gantt chart for tasks in Botanical garden should look like.
Source data and R code are available on the GitHub.
No comments:
Post a Comment