PlotReopensByAgent <- structure(
function # Create a plot of the number of reopens by agent
##############################################################################
# File: PlotReopensByAgent.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 number of reopens 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.
... ##<< 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$reopens[dF$reopens == "nan.0"] <- NA
dF$value <- as.numeric(dF$reopens)
#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<< Wait 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 <- "Number of Reopens"
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
## reopens resolve their assigned issues effectively. 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 number of reopens for the entire data frame. Agents whose
## medians are below this line may be more effective at researching and resolving customer
## issues. Further, agents that are more effective could
## be considered as 'trainers' for new staff.
#Boxplot of assignee_name and resolution time
val <- data.frame(z = mean(dF$value, na.rm = T))
g <- ggplot(dF, aes(x = assignee_name, y = (value),
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.