PlotResolutionTimeByAgent <- structure(
function # Create a plot of the resolution time by date
##############################################################################
# File: PlotResolutionTimeByAgent.R
##author<< Steven H. Ranney
## Contact: \email{Steven.Ranney@gmail.com}
# Created: 12/30/14
# Last Edited: 12/31/14 by SHR
##description<< This function plots the resolution time (in hours) and produces a box
## plot of those values for each \code{assignee_name} in the \code{dF}. The
## call volume of an agent is produced.
#
# TODO: add RData for example
# TODO: add testing section
###############################################################################
(dF, ##<< The dataFrame for which to plot resolution time by date level.
resTime = "first", ##<< A character vector that indicates which resolution time
## within business hours to plot. Other values include
## \code{"full"}.
... ##<< Arguments to be passed to other functions. Specifically, this can take
## the form of identifying which \code{date} value is of interest. For example
## the sample datasets provided all had either at least \code{assigned_at}
## or \code{created_at} values. The \code{\link{AssignDateAndDay}} can used
## either of these values as the date of interest.
){
dF <- AssignDateAndDay(dF, ...)
#Eliminate rows where there is no date assigned
dF <- dF[which(!is.na(dF$assignedDate)), ]
#Handling 'nan.0' values
dF$first_resolution_time_in_minutes_within_business_hours[dF$first_resolution_time_in_minutes_within_business_hours == "nan.0"] <- NA
dF$full_resolution_time_in_minutes_within_business_hours[dF$full_resolution_time_in_minutes_within_business_hours == "nan.0"] <- NA
if(resTime == "first") dF$value <- as.numeric(dF$first_resolution_time_in_minutes_within_business_hours)
if(resTime == "full") dF$value <- as.numeric(dF$full_resolution_time_in_minutes_within_business_hours)
#Count how many calls each assignee_name had
nameVol <- aggregate(dF$dayOfWeek, by = list(dF$assignee_name), length)
names(nameVol) <- c("assignee_name", "volume")
nameVol$volume <- nameVol$volume/10
if(length(which(is.na(dF$value))) == nrow(dF)){
stop(print("Data frame has no data to display"))
} else {
##details<< Resolution time in all sample dataFrames is \code{factor}; this function
## converts apparently numeric values to \code{as.numeric}.
##details<< This functions converts values that are \code{nan.0} to \code{NA}.
##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 <- NA
if(resTime == "first") ylabel <- "First resolution (hours)"
if(resTime == "full") ylabel <- "Full resolution (hours)"
xlabel <- "Assignee name"
##details<< Plots are generated by the function \code{\link{ggplot}}
##details<< The blue line in the top plot of the window is the number calls
## received by each \code{assignee_name}. Assignees with high volume and low
## resolution times are the most efficient agents. The combination of these
## plots can tell a manager which employees are most efficient at resolving
## calls.
##details<< The red line in the bottom plot of the window produced from this function
##is the mean resolution-time value for the entire data frame. Agents whose
## medians are below this line may be more effective at resolving customer
## issues. Further, agents that are more effective at resolving issues could
## be considered as 'trainers' for new staff.
#Boxplot of assignee_name and resolution time
val <- data.frame(z = mean(dF$value/60, na.rm = T))
g <- ggplot(dF, aes(x = assignee_name, y = (value/60),
group = assignee_name))
p1 <- g + geom_boxplot(mapping = NULL, data = dF, stat = "boxplot",
outlier.colour = "red", outlier.shape = 16,
outlier.size = 2) +
labs(ylab(ylabel)) + labs(xlab(xlabel)) + # + labs(ggtitle("Resolution time")) +
geom_hline(aes(yintercept = z), val, colour = "red")
p1 <- p1 + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
#Line plot of assignee_name and call volume
volPlot <- ggplot(nameVol, aes(x = assignee_name, y = volume,
group = 1))
p2 <- volPlot + geom_line(colour = "navyblue", size = 1.01) +
labs(ylab("Call volume (x10)"))# + labs(xlab(xlabel))# + labs(ggtitle("Resolution time"))
p2 <- p2 + theme(axis.ticks.x = element_blank(), axis.text.x = element_blank(),
axis.title.x = element_blank())
allPlots <- PlotMultipleObjects(p2, p1)
return(allPlots)
} #end else
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.