diff --git a/R/downloadsStats-utils.R b/R/downloadsStats-utils.R index 507b48d..a3ae4b7 100644 --- a/R/downloadsStats-utils.R +++ b/R/downloadsStats-utils.R @@ -177,7 +177,7 @@ processPckg <- function(pckg.lst, t0=lastyear.date(), t1=today(), opts=list(), d t1 <- dates[[2]] # check options... - validOpts <- tolower(c("nostatic","nointeractive", "nocombined", "noMovAvg","noConfBand", "noSummary", "compare")) + validOpts <- tolower(c("nostatic","nointeractive", "nocombined", "noMovAvg","noConfBand", "onlyConfBand", "noSummary", "compare")) checkOpts(opts,validOpts) @@ -202,7 +202,7 @@ processPckg <- function(pckg.lst, t0=lastyear.date(), t1=today(), opts=list(), d } else { ### Plots # set defaults - cmb <- TRUE; noCBs <- FALSE; noMAvgs <- FALSE + cmb <- TRUE; noCBs <- FALSE; noMAvgs <- FALSE; onlyCB <- FALSE ## static plots if ('nostatic' %in% tolower(opts)) { @@ -212,8 +212,9 @@ processPckg <- function(pckg.lst, t0=lastyear.date(), t1=today(), opts=list(), d if ('nocombined' %in% tolower(opts)) cmb <- FALSE if ('noconfband' %in% tolower(opts)) noCBs <- TRUE if ('nomovavg' %in% tolower(opts)) noMAvgs <- TRUE + if ('onlyconfband' %in% tolower(opts)) onlyCB <- TRUE - staticPlots(pckg.stats.total, combinePlts=cmb, noMovAvg=noMAvgs, noConfBands=noCBs, device=device,dirSave=dirSave) + staticPlots(pckg.stats.total, combinePlts=cmb, noMovAvg=noMAvgs, noConfBands=noCBs, onlyConfBand=onlyCB, device=device,dirSave=dirSave) } ### interactive plots @@ -237,7 +238,7 @@ processPckg <- function(pckg.lst, t0=lastyear.date(), t1=today(), opts=list(), d } if ( "compare" %in% tolower(opts) ) { - comparison.Plt(pckgDwnlds.lst, t0,t1, cmb,noMAvgs,noCBs,device=device,dirSave=dirSave) + comparison.Plt(pckgDwnlds.lst, t0,t1, cmb,noMAvgs,noCBs,onlyCB,device=device,dirSave=dirSave) return(invisible(pckgDwnlds.lst)) } } diff --git a/R/plotting-utils.R b/R/plotting-utils.R index 94bd3ae..ac5c02e 100644 --- a/R/plotting-utils.R +++ b/R/plotting-utils.R @@ -149,11 +149,11 @@ axes.TimePlt <- function(tot.days,pckg.stats.total,yaxis.side=4) { ### static plots staticPlots <- function(pckg.stats.total, #pckg.stats.lstmnt, - device="PDF", - fileName=paste0("DWNLDS_",pckg.stats.total$package[1],".",tolower(device)), - dirSave=NULL, - combinePlts=FALSE, noMovAvg=FALSE, noConfBands=FALSE, - cutOff.pts=250, dbg=FALSE){ + device="PDF", + fileName=paste0("DWNLDS_",pckg.stats.total$package[1],".",tolower(device)), + dirSave=NULL, + combinePlts=FALSE, noMovAvg=FALSE, noConfBands=FALSE, + onlyConfBand=FALSE,cutOff.pts=250, dbg=FALSE){ #' function that generates visual trends of the package downloads logs from CRAN, it will generate 4 plots: two histograms, a pulse plot and the main plot is a plot of the downloads as a function of time #' @param pckg.stats.total total downloads from the package #' @param device string to select the output format: 'PDF'/'PNG'/'JPEG' or 'screen' @@ -313,7 +313,11 @@ staticPlots <- function(pckg.stats.total, #pckg.stats.lstmnt, abline(h=mean(pckg.stats.total$count), lty=2) # pulse plot - plot(pckg.stats.total$date,(pckg.stats.total$count), type="S", lwd=0.5, col="gray10", ann=FALSE) + if (!onlyConfBand) { + plot(pckg.stats.total$date,(pckg.stats.total$count), type="S", lwd=0.5, col="gray10", ann=FALSE) + } else { + plot(pckg.stats.total$date,(pckg.stats.total$count), type="n", ann=FALSE) + } #abline(h=mean(pckg.stats.total$count), lty=2) #abline(h=mean(pckg.stats.total$count)+sd(pckg.stats.total$count), lty=3) #abline(h=mean(pckg.stats.total$count)-sd(pckg.stats.total$count), lty=3) @@ -344,21 +348,34 @@ staticPlots <- function(pckg.stats.total, #pckg.stats.lstmnt, subsample.date <- pckg.stats.total$date[1:tot.days%%nbrPts == 0] subsample.counts <- pckg.stats.total$count[1:tot.days%%nbrPts == 0] message("Nbr of data points (",tot.days,") exceeds internal cut-off (",cutOff.pts,"); plot will resub-sample to ",nbrPts,".") - plot(subsample.date,subsample.counts, 'b', cex=.5, - xlim=c(fst.date,lst.date), - ylim=c(0,max.downloads*1.05) , - ann=FALSE, axes=FALSE ) - lines(pckg.stats.total$date, (pckg.stats.total$count), - lwd=0.35, col='gray', - #lty=3,lwd=0.35, - xlim=c(fst.date,lst.date), - ylim=c(0,max.downloads*1.05) , - ann=FALSE)#, axes=FALSE ) + if (!onlyConfBand) { + plot(subsample.date,subsample.counts, 'b', cex=.5, + xlim=c(fst.date,lst.date), + ylim=c(0,max.downloads*1.05) , + ann=FALSE, axes=FALSE ) + lines(pckg.stats.total$date, (pckg.stats.total$count), + lwd=0.35, col='gray', + #lty=3,lwd=0.35, + xlim=c(fst.date,lst.date), + ylim=c(0,max.downloads*1.05) , + ann=FALSE)#, axes=FALSE ) + } else { + plot(pckg.stats.total$date,(pckg.stats.total$count), type="n", + xlim=c(fst.date,lst.date), ylim=c(0,max.downloads*1.05), + ann=FALSE, axes=FALSE) + } } else { - plot(pckg.stats.total$date, (pckg.stats.total$count), 'b', - xlim=c(fst.date,lst.date), - ylim=c(0,max.downloads*1.05) , - ann=FALSE, axes=FALSE ) + if (!onlyConfBand) { + plot(pckg.stats.total$date, (pckg.stats.total$count), 'b', + xlim=c(fst.date,lst.date), + ylim=c(0,max.downloads*1.05) , + ann=FALSE, axes=FALSE ) + } else { + plot(pckg.stats.total$date,(pckg.stats.total$count), type="n", + xlim=c(fst.date,lst.date), + ylim=c(0,max.downloads*1.05) , + ann=FALSE, axes=FALSE) + } } if (!noMovAvg) { @@ -397,15 +414,19 @@ staticPlots <- function(pckg.stats.total, #pckg.stats.lstmnt, deltaT <- max(1,time.units[largest.timeUnit]) if (dbg) print(deltaT) # if (tot.days <= cutOff.pts) { - emphasize(pckg.stats.total$date,pckg.stats.total$count, deltaT, fst.date,lst.date,0,max.downloads*1.05, "darkblue", .85) + if (!onlyConfBand) + emphasize(pckg.stats.total$date,pckg.stats.total$count, deltaT, fst.date,lst.date,0,max.downloads*1.05, "darkblue", .85) # } else { # emphasize(subsample.date,subsample.counts, deltaT, fst.date,lst.date,0,max.downloads*1.05, "darkblue", .85) # } - if ( (largest.timeUnit > 1) & (time.units[largest.timeUnit-1] != 30) ) - emphasize(pckg.stats.total$date,pckg.stats.total$count, time.units[largest.timeUnit-1], fst.date,lst.date,0,max.downloads*1.05, "darkorange", 1) + if (!onlyConfBand) + if ((largest.timeUnit > 1) & (time.units[largest.timeUnit-1] != 30)) + emphasize(pckg.stats.total$date,pckg.stats.total$count, time.units[largest.timeUnit-1], fst.date,lst.date,0,max.downloads*1.05, "darkorange", 1) # last month trend... - if (deltaT != 30) emphasize(pckg.stats.total$date,pckg.stats.total$count, 30, fst.date,lst.date,0,max.downloads*1.05, "darkred", 1.5) + if (!onlyConfBand) + if (deltaT != 30) + emphasize(pckg.stats.total$date,pckg.stats.total$count, 30, fst.date,lst.date,0,max.downloads*1.05, "darkred", 1.5) #print(pckg.stats.lstmnt$date) # stats from last month @@ -457,9 +478,11 @@ staticPlots <- function(pckg.stats.total, #pckg.stats.lstmnt, # add maximum download # loop over possible dates showing same maximum number of downloads - for (i in 1:length(max.dwlds.date)) { - points(max.dwlds.date[i],max.downloads, col='darkred', pch=19) - text(max.dwlds.date[i],max.downloads*1.035,max.downloads, col='darkred') + if (!onlyConfBand) { + for (i in 1:length(max.dwlds.date)) { + points(max.dwlds.date[i],max.downloads, col='darkred', pch=19) + text(max.dwlds.date[i],max.downloads*1.035,max.downloads, col='darkred') + } } # Close file @@ -577,7 +600,7 @@ interactivePlots <- function(downloads.data, mytitle=paste(downloads.data$packag ###### Comparison Plot -comparison.Plt <- function(pckgDwnlds.lst, t0,t1, cmb=TRUE,noMAvgs=FALSE,noCBs=FALSE, device="PDF",dirSave=NULL){ +comparison.Plt <- function(pckgDwnlds.lst, t0,t1, cmb=TRUE,noMAvgs=FALSE,noCBs=FALSE,onlyConfBand=FALSE, device="PDF",dirSave=NULL){ #' function that generates a comparison plot among several packages #' @param pckgDwnlds.lst nested list containing the several packages to process #' @param t0 initial date @@ -585,6 +608,7 @@ comparison.Plt <- function(pckgDwnlds.lst, t0,t1, cmb=TRUE,noMAvgs=FALSE,noCBs=F #' @param cmb boolean flag, indicating whether the plots are shown in the same (default) graph or not #' @param noMAvgs boolean flag, indicating whether moving averages are displayed (default) or NOT --set to TRUE-- #' @param noCBs boolean flag, indicating whether shaded confidence intervals are displayed (default) or NOT --set to TRUE-- +#' @param onlyConfBand boolean flag, indicating whether only confidence bands are displayed (no data points) --set to TRUE-- #' @param device string to select the output format: 'PDF'/'PNG'/'JPEG' or 'screen' #' @param dirSave specify a valid directory where to save the file #' @@ -668,9 +692,15 @@ comparison.Plt <- function(pckgDwnlds.lst, t0,t1, cmb=TRUE,noMAvgs=FALSE,noCBs=F if (cmb) par(new=TRUE) yvar <- (pckgDwnlds.lst[[j]]$count) if (!cmb) yrange <- c(min(yvar),max(yvar)) - plot(pckgDwnlds.lst[[j]]$date, yvar, 'o', col=j, lwd=0.35, cex=0.35, - xlim=xrange, ylim=yrange, - ann=!cmb, axes=!cmb ) + if (!onlyConfBand) { + plot(pckgDwnlds.lst[[j]]$date, yvar, 'o', col=j, lwd=0.35, cex=0.35, + xlim=xrange, ylim=yrange, + ann=!cmb, axes=!cmb ) + } else { + plot(pckgDwnlds.lst[[j]]$date, yvar, type='n', + xlim=xrange, ylim=yrange, + ann=!cmb, axes=!cmb ) + } if (!noCBs) confBand(pckgDwnlds.lst[[j]]$date,pckgDwnlds.lst[[j]]$count, t0,t1, 0,counts.max,