KEEP THIS FOR THE GRAPHS, EVEN THOUGH THE BUSINESS KNOWLEDGE IS INACCURATE DB.merged[, c("wk1.rd", "wk1.sd") := FALSE] DB.merged[inweek(download_date, startDate), wk1.sd := TRUE, by=upc] DB.merged[inweek(download_date, releaseDate), wk1.rd := TRUE, by=upc] DB.merged[(wk1.rd), wk1.rd.tot := sum(t.DailyCount.byupc, na.rm=TRUE), by=upc] DB.merged[(wk1.sd), wk1.sd.tot := sum(t.DailyCount.byupc, na.rm=TRUE), by=upc] wk1Cols <- c("streamsW1", "adSuppStreamsW1", "totalStreamsW1", "wk1.rd.tot", "wk1.sd.tot") Week1 <- unique(DB.merged[(!is.na(wk1.rd.tot) & !is.na(wk1.sd.tot)) , .SD, .SDcols=c("upc", "release", "genre", "artist", "format", wk1Cols)]) Week1[, disc.rd := wk1.rd.tot - totalStreamsW1] Week1[, disc.sd := wk1.sd.tot - totalStreamsW1] Week1[, week := 1] # ---- DB.merged[, c("wk2.rd", "wk2.sd") := FALSE] DB.merged[inweek(download_date, startDate), wk2.sd := TRUE, by=upc] DB.merged[inweek(download_date, releaseDate), wk2.rd := TRUE, by=upc] DB.merged[(wk2.rd), wk2.rd.tot := sum(t.DailyCount.byupc, na.rm=TRUE), by=upc] DB.merged[(wk2.sd), wk2.sd.tot := sum(t.DailyCount.byupc, na.rm=TRUE), by=upc] wk2Cols <- c("streamsW2", "adSuppStreamsW2", "totalStreamsW2", "wk2.rd.tot", "wk2.sd.tot") Week2 <- unique(DB.merged[(!is.na(wk2.rd.tot) & !is.na(wk2.sd.tot)) , .SD, .SDcols=c("upc", "release", "genre", "artist", "format", wk2Cols)]) Week2[, disc.rd := wk2.rd.tot - totalStreamsW2] Week2[, disc.sd := wk2.sd.tot - totalStreamsW2] Week2[, week := 2] # ---- setnames(Week1, gsub("W(k)?1\\.?", "", names(Week1), ignore.case=TRUE)) setnames(Week2, gsub("W(k)?2\\.?", "", names(Week1), ignore.case=TRUE)) Week <- rbind(Week1, Week2) Week <- Week[!is.na(totalStreams)] Week[, week := factor(week)] Week[, c("ymin", "ymax") := list(min(totalStreams, sd.tot, na.rm=TRUE), max(sd.tot, totalStreams, na.rm=TRUE)), by=upc] Week[, updown := factor(ymax > totalStreams, labels=c("Red", "Green"))] Week[, genre := factor(genre)] Week[, c("Name", "release") := list(substr(release, 1, 10), NULL)] Week[, list(N=lunique(week)), by=upc] [!(N <= 1)] Week <- Week[Week[, .I[lunique(week)>=2], by=upc]$V1] # Week[release=="Holy Ghosts (Pro Patria Mori / Orchestral Reworkings Live at the Union Chapel) Deluxe Edition with Track Commentary", release:="Long Name"] library(ggplot2) ggplot(Week, aes(x=as.numeric(week))) + geom_errorbar(aes(ymin=ymin, ymax=ymax, color=updown, size=scale(abs(disc.sd))), width=.2, size=1) + geom_point(aes(y=totalStreams, color=genre)) + geom_line(aes(y=totalStreams, color=genre)) + theme(axis.text = element_text(angle=60)) + facet_grid(.~artist) scale_y_log10() are(Week) ggplot(msePlot, aes(x=model, y=mn, ymax=max(mn)+max(sd), colour=split)) + geom_errorbar(aes(ymin=mn-sd, ymax=mn+sd), width=.4, position=pd) + geom_point(position=pd, size=2) + ylab("Error") + ylab(aes(size=2)) + xlab("") + ggtitle("Cross-Validation: Means ± SD of Errors") + theme(plot.title = element_text(size = 10)) + theme(legend.direction="horizontal", legend.position=c(0.68, 0.88)) + theme(legend.background=element_rect(colour='blue', fill='white', size=0.5*sc, linetype='solid'), legend.text=element_text(size=5, hjust=0, vjust=0.5, face='plain'), legend.key=element_rect(fill="light grey", size=10*sc, linetype=0)) + scale_colour_manual(values=c("#FF4062","#100020"), name="", labels=c("Training Error", "Testing Error"))