## quick and simple R chart attempt to look better than the gnuplot example ## ## $Id: debian_bts_chart.R,v 1.1 2005/02/21 21:51:32 edd Exp $ library(gplots) # for smartlegend, requires r-cran-gregmisc doPlots <- function(Data, filename) { ## attach the data.frame, so we can say 'date' instead of Data[,"date"] attach(Data) ## set graphical parameter: oldpar <- par(mfrow=c(4,1), # four rows of charts mar=c(2.5,2.5,0.5,1), # tighter margins oma=c(0,0,2,0), # outer margin cex.axis=0.95 ) ## plot binary over date as a line, set range for nsrc and nbin plot(date, nbin, type='l', ylim=range(nsrc,nbin,na.rm=TRUE), col="darkblue", ylab="") ## add a line for nsrc lines(date, nsrc, col="darkgreen") smartlegend("left", "top", c("Binary Pkgs", "Source Pkgs"), col=c("darkblue","darkgreen"), bty="n", lty=1, inset=0.001) plot(date, nact, type='l', ylim=range(nact,narch,na.rm=TRUE), col="darkblue", ylab="") lines(date, narch, col="darkgreen") smartlegend("left", "top", c("Active Bugs", "Archived Bugs"), col=c("darkblue","darkgreen"), bty="n", lty=1, inset=0.001) plot(date, actsrc, type='l', ylim=range(actsrc,actbin,na.rm=TRUE), col="darkblue", ylab="") lines(date, actbin, col="darkgreen") smartlegend("left", "bottom", c("Active Pkgs / Source", "Active Bugs / Binary"), col=c("darkblue","darkgreen"), bty="n", lty=1, inset=0.001) plot(date, archsrc, type='l', ylim=range(archsrc,archbin,na.rm=TRUE), col="darkblue", ylab="") lines(date, archbin, col="darkgreen") smartlegend("left", "bottom", c("Archived Pkgs / Source", "Archived Bugs / Binary"), col=c("darkblue","darkgreen"), bty="n", lty=1, inset=0.001) title(paste("Bug statistics over time for" ,filename), outer=TRUE, cex.main=1.4) ## reset graph paramters par(oldpar) } loopDirectory <- function(datadir = "/tmp/data", chartdir = "/tmp/charts") { Files <- list.files(datadir, "*.csv") for (i in seq(along=Files)) { file <- Files[i] name <- gsub(".csv", "", file) # sub out the trailing .csv cat("Looking at", file, "\n") ## read via read.table into a data frame, supply colnames ## data column format, per Wouter's email: ## * date, in ISO format ## * number of source packages ## * number of binary packages ## * number of active bugs ## * number of archived bugs ## * average number of active bugs per source package ## * average number of active bugs per binary package ## * average number of archived bugs per source package ## * average number of archived bugs per binary package Data <- read.table(file=paste(datadir, file, sep="/"), sep=" ", header=FALSE, col.names=c("date", "nsrc", "nbin", "nact", "narch", "actsrc", "actbin", "archsrc", "archbin")) ## turn the first column of dates into a Date object ## this will now automatically label the x axis Data$date <- as.Date(as.character(Data$date), "%Y%m%d") ## open a pdf file for output pdf(file=paste(chartdir, gsub(".csv", ".pdf", file), sep="/"), width=8, height=10) doPlots(Data, name) # and plot dev.off() # and close device => file created ## idem for a png bitmap(file=paste(chartdir, gsub(".csv", ".png", file), sep="/"), type="png16m", height=10, width=8) doPlots(Data, name) # and plot dev.off() # and close device => file created } } loopDirectory()