Sunday, May 1, 2016

Making Gantt chart for the Botanical garden project

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:


taskstartendaxislabel
Collecting2017/03/012017/03/052017/01/01Jan
Collecting2017/04/012017/04/052017/02/01Feb
Collecting2017/05/012017/05/052017/03/01Mar
Collecting2017/06/012017/06/052017/04/01Apr
Collecting2017/07/012017/07/052017/05/01May
Collecting2017/08/012017/08/052017/06/01Jun
Collecting2017/09/012017/09/052017/07/01Jul
Pot care2017/05/062017/09/062017/08/01Aug
Planting2017/03/062017/03/112017/09/01Sep
Planting2017/04/062017/04/112017/10/01Oct
Planting2017/09/062017/09/112017/11/01Nov
Photo-shoot2017/05/012017/08/012017/12/01Dec
Making herbar2017/05/012017/07/01
Data base2017/08/012017/12/01
Web-site2017/01/012017/03/01
Web-site2017/10/022017/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.