This R Markdown document is a quick example of how to create your basic Gantt Chart using R. Run lines that are commented out by deleting the # (hashtag) at the start of the line.
plotrix
package in RIf you haven’t installed the package, this line will download and install it for you.
install.packages("plotrix")
Load the package for use:
library(plotrix)
You can add more objectives to the chart. Make sure to have the same length of dates (start and end) and labels as below.
Ymd.format<-"%Y/%m/%d"
gantt.info<-list(labels=c("Contract Preparation","Rapid Literature Review","CITI Training","IRB Addendum & Inclusion","Data Download","Data Analysis","Data Products"),
starts=as.POSIXct(strptime(c("2014/06/01","2014/06/04","2014/06/07","2014/06/19","2014/06/29","2014/07/01","2014/07/23"),
format=Ymd.format)),
ends=as.POSIXct(strptime(c("2014/06/16","2014/06/19","2014/06/17","2014/06/29","2014/07/02","2014/07/22","2014/08/05"),
format=Ymd.format)),
priorities=c(1,4,3,2,3,2,1))
months <- seq(as.Date("2014/06/01", "%Y/%m/%d"), by="month", length.out=8)
monthslab <- format(months, format="%b")
vgridpos<-as.POSIXct(months,format=Ymd.format)
vgridlab<-monthslab
colfunc <- colorRampPalette(c("red", "darkgoldenrod1"))
timeframe <- as.POSIXct(c("2014/06/01","2014/09/01"),format=Ymd.format)
Last step is to plot all your values and save the file as a pdf
gantt.chart(gantt.info, taskcolors=colfunc(4),xlim=timeframe, main="Gantt Chart for Fieldwork 2014",
priority.legend=TRUE,vgridpos=vgridpos,vgridlab=vgridlab,hgrid=TRUE)
Finally, you can save your graph by running these lines.
dev.copy(pdf, width = 8, height = 6, paper = "special")
dev.off()