I have a dataframe that contains Date, Day-of-the-Week (categorical), and number of calls (numeric). I'm trying to do analytics on how what the distribution of call volume is by Day-of-the-week. Using the lattice package I was able to create a bar chart, but still need some additional help:
How can I order/sort the Day-of-the-Week variables that appear in my barchart (I'd like it to start on Sat, then Sun, then Mon,...)?
I'd also like to transpose the distribution so that the bar charts are vertical as opposed to horizontal.
Finally, how can I add a box-and-wisker plot? Should I still use tapply for this?
Thanks!
Here's what I've done so far:
LatinoDRTVdata <- read.csv("//dishfs1/Marketing/Mktg_Analytics/Team Member folders/Ryan_Chase/Ad Hoc/Latino DRTV Normalized Calls.csv")
#look at the first 10 rows
head(LatinoDRTVdata)
#look at the full dataset
LatinoDRTVdata
#look at the column names
colnames(LatinoDRTVdata)
#check the class of the Normalized.Latino.DRTV.call.volume column
class(LatinoDRTVdata$Normalized.Latino.DRTV.call.volume)
##make the call volume a numeric vector
LatinoDRTVdata$Normalized.Latino.DRTV.call.volume <- as.numeric(LatinoDRTVdata$Normalized.Latino.DRTV.call.volume)
#now check the class again
class(LatinoDRTVdata$Normalized.Latino.DRTV.call.volume)
(LatinoDRTVdata$Normalized.Latino.DRTV.call.volume)
#194 calls is the mean volume regardless of the day
mean(LatinoDRTVdata$Normalized.Latino.DRTV.call.volume)
#Day of the week is a factor
class(LatinoDRTVdata$Day.of.the.Week)
summary(LatinoDRTVdata)
str(LatinoDRTVdata)
#histogram of daily Latino DRTV call volume
hist(LatinoDRTVdata$Normalized.Latino.DRTV.call.volume)
#find the mean of each day
Daily.Latino.DRTV.Distribution<- tapply(LatinoDRTVdata$Normalized.Latino.DRTV.call.volume,LatinoDRTVdata$Day.of.the.Week,mean)
Daily.Latino.DRTV.Distribution
Daily.Latino.DRTV.Distribution$ormalized.Latino.DRTV.call.volume
##check that a new object has been added
ls()
str(Daily.Latino.DRTV.Distribution)
#make sure you install the lattice package for the graphics
#load the lattice package
library(lattice)
barchart(Daily.Latino.DRTV.Distribution)
here is the top 10 rows of my data:
> head(LatinoDRTVdata)
Date Day.of.the.Week Normalized.Latino.DRTV.call.volume
1 3/1/2013 Friday 384
2 3/2/2013 Saturday 277
3 3/3/2013 Sunday 178
4 3/4/2013 Monday 400
5 3/5/2013 Tuesday 410
6 3/6/2013 Wednesday 404
>