PlotCallVolumeByDay <- structure(
function # Create a plot of the resolution time by day of week
##############################################################################
# File: PlotResolutionTimeByDay.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 resolution time (in hours) and produces
## a box plot of those values as a function of the day of week.
#
# 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)), ]
#aggregate call volume by date
volData <- aggregate(dF$dayOfWeek, by = list(dF$assignedDate), length)
names(volData) <- c("assignedDate", "totalCalls")
volData <- volData[order(volData$assignedDate), ]
volData$dayOfWeek <- weekdays(volData$assignedDate)
#Ordering the dayOfWeek factors correctly
volData$dayOfWeek <- factor(volData$dayOfWeek, levels=c("Monday", "Tuesday",
"Wednesday", "Thursday",
"Friday", "Saturday",
"Sunday"))
##details<< This functions converts dates that are not represented in the data
## frame to \code{0} values. However, \code{0} value dates are only 'filled in;'
## that is, the function only fills in dates. It does not extend the date field.
## For example, if the data frame has dates \code{2014-01-01}, \code{2014-01-03},
## and \code{2014-01-05}, this function fills in the date gaps.
ylabel <- "Number of calls/day"
xlabel <- "Day of Week"
##details<< Plots are generated by the function \code{\link{ggplot}}
g <- ggplot(volData, aes(x = dayOfWeek, y = totalCalls, fill = dayOfWeek))
p1 <- g + geom_boxplot(mapping = NULL, data = volData, stat = "boxplot",
position = "dodge", outlier.colour = "red", outlier.shape = 16,
outlier.size = 2, notch = TRUE) +
labs(ylab(ylabel)) + labs(xlab(xlabel)) + #labs(ggtitle("Resolution time")) +
theme(legend.position="none") +
scale_fill_brewer()
return(p1)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.