PlotScoreByCallVolume <- structure(
function # Create a plot of the score by call volume
##############################################################################
# File: PlotScoreByCallVolume.R
##author<< Steven H. Ranney
## Contact: \email{Steven.Ranney@gmail.com}
# Created: 12/30/14
# Last Edited: 12/30/14 by SHR
##description<< This function plots the satisfaction score and produces a plot
## of those values as a function of call volume.
#
# TODO: add RData for example
# TODO: add testing section
###############################################################################
(dF, ##<< The dataFrame for which to convert \code{satisfaction_score} into a
## number.
... ##<< 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.
){
##details<< This function calls the \code{\link{ConvertSatisfactionScoreToNumber}}
## function to assign the \code{day} values used.
dF <- ConvertSatisfactionScoreToNumber(dF)
dF <- AssignDateAndDay(dF, ...)
#Eliminate rows where there is no date assigned
dF <- dF[which(!is.na(dF$assignedDate)), ]
#aggregate call volume by date
volData <- aggregate(dF$dayOfWeek, by = list(dF$assignedDate), length)
names(volData) <- c("assignedDate", "totalCalls")
volData <- volData[order(volData$assignedDate), ]
#aggregate scores by Date
scoreData <- aggregate(dF$scoreNumber, by = list(dF$assignedDate), mean, na.rm = T)
names(scoreData) <- c("assignedDate", "meanScore")
scoreData <- scoreData[order(scoreData$assignedDate), ]
allData <- cbind(volData, scoreData)
if(length(which(is.na(dF$scoreNumber))) == nrow(dF)){
stop("There is no satisfaction data in this data frame.")
} else {
##details<< Plots are generated by the function \code{\link{ggplot}}
##details<< This function uses a linear model to evaluate the relationship between
## satisfaction score and call volume (i.e., calls per day). If the red line
## (the result of the \code{\link{lm}} in the produced plot trends down, then
## resolution time has a negative affect on satisfaction score. If the red
## line is parallel or very near to parallel, then there is no relationship
## between satisfaction score and resolution time.
##details<< In most cases, there are very few or no satisfaction scores. As a
## result, these data are sparse.
xlabel <- "Call volume (calls/day)"
ylabel <- "Satisfaction score (numeric)"
#Create a linear model of score as a function of wait time (hours)
lmMod <- lm(allData$meanScore~allData$totalCalls)
g <- ggplot(allData, aes(x = totalCalls, y = meanScore))#, fill = dayOfWeek))
p1 <- g + geom_point() + labs(ylab(ylabel)) + labs(xlab(xlabel)) +
geom_abline(intercept=lmMod$coefficients[1], slope=lmMod$coefficients[2],
colour = "red", size = 1.01)
} # end else
return(p1)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.