R/PlotReopensByPriority.R

  PlotReopensByPriority <- structure(
  function 
  ##title<< Plot hours to resolution time by priority 

  ##############################################################################
  # File:  PlotReopensByPriority.R
  ##author<<  Steven H. Ranney
  ## Contact: \email{Steven.Ranney@gmail.com}
  # Created: 12/21/14  
  # Last Edited: 12/28/14 by SHR
  ##description<< This function plots the number of reopens and produces a box 
  ## plot of those values as a function of \code{priority} level. 
  #
  # TODO: add RData for example
  # TODO: add testing section
  ###############################################################################

  (dF ##<< The dataFrame for which to plot resolution time by priority level.
  ){
  
  #Ordering the priority factors correctly
  dF$priority <- factor(dF$priority, levels=c("-", "Low", "Normal", "High", "Urgent"))
  
  #Handling 'nan.0' values
  dF$reopens[dF$reopens == "nan.0"] <- NA
  dF$value <- as.numeric(dF$reopens)
 
  if(length(which(is.na(dF$value))) == nrow(dF)){
    stop(print("There is no reopen data in this data frame."))
    } else {
 
  ##details<< This functions converts values that are \code{nan.0} to \code{NA}.
  
  ##details<< Priority levels in some of the sample data are represented by five 
  ## different values: \code{High}, \code{Low}, \code{Normal}, \code{Urgent}, 
  ## and \code{-}. Review of the sample data showed that the \code{-} priority 
  ## level could not be determined to match any other level.
    
  ##details<< Boxes in the plot that is produced from this function can help
  ## managers understand the number of reopens by \code{priority} level.  If the 
  ## notches in a box overlap the heavy bar (i.e., the median number of reopens)
  ## in an adjacent box, then the number of reopens for that priority level is \emph{not}
  ## significantly different than the number of reopens in the adjacent box.  This 
  ## provides a quick, easy method of determining if \code{priority} level really 
  ## has an affect on the number of reopens.
    
  ##details<< The red dots on a plot indicate outliers in the data set.  In the 
  ## \code{\link{geom_boxplot}} documentation, outliers are defined as data points 
  ## fall outside of \emph{1.5 * IQR} where \emph{IQR} stands for the "Inter-Quartile
  ## Range" of the data.

  ylabel <- "Number of reopens" 
  xlabel <- "Priority level"
  
  ##details<< Plots are generated by the function \code{\link{ggplot}}
  g <- ggplot(dF, aes(x = priority, y = (value), fill = priority))
  
  p1 <- g + geom_boxplot(mapping = NULL, data = dF, stat = "boxplot", 
                    position = "dodge", outlier.colour = "red", outlier.shape = 16, 
                    outlier.size = 2, notch = TRUE) + 
      labs(ylab(ylabel)) + labs(xlab(xlabel)) + labs(ggtitle("Wait time")) + 
      scale_fill_brewer()
    } # end else
  
  return(p1)
    
  })  
stevenranney/ispiranteRanney documentation built on May 30, 2019, 4:46 p.m.