--- end --- This is stuff I had put together, then reworked and did something differently. The graph parts might still be useful ~~~~~~~ ## ALTERNATE --- UNUSED, BUT GOOD THOUGHT PROCESS ## ## Filter to just iTunes--"DA" DT.grid.apprvd_titles <- DT.weekly_avg.apprvd_titles[storeid == 1 & transac_type_abbr == "DA"] ## Convert week_number to factor and paidunits to the average of the cut group DT.grid.apprvd_titles[, week_number := factor(week_number)] DT.grid.apprvd_titles[, paidunits_avg_of_group_in_range := as.num.as.char(cut2(paidunits, cuts=cuts.paidunits, levels.mean=TRUE, digits=2))] DT.grid.apprvd_titles <- dcast.data.table(DT.grid.apprvd_titles, releaseid ~ week_number, value.var="paidunits_avg_of_group_in_range") Weeklycols <- c(setdiff(names(DT.grid.apprvd_titles), "releaseid")) DT.grid.apprvd_titles[, (Weeklycols) := lapply(.SD, removeNA, replace=0L), .SDcols=Weeklycols] DT.grid.apprvd_titles[, (Weeklycols) := lapply(.SD, Hmisc::cut2, cuts=cuts, levels.mean=TRUE, digits=1), .SDcols=Weeklycols] releaseid_ordering <- DT.grid.apprvd_titles[order(get(tail(names(DT.grid.apprvd_titles),1)), decreasing=TRUE)]$releaseid DT.grid.apprvd_titles[, releaseid := factor(as.character(releaseid), levels=releaseid_ordering)] DT.grid.apprvd_titles <- reshape2::melt(DT.grid.apprvd_titles, id.var="releaseid", var="week_number", val="paidunits") DT.grid.apprvd_titles[, paidunits := factor(paidunits)] setkeyIfNot(DT.grid.apprvd_titles, releaseid) DT.grid.apprvd_titles[, levels(paidunits), verbose=FALSE] DT.grid.apprvd_titles releaseid_above_3 <- DT.weekly_avg.apprvd_titles[week_number == max(week_number) & paidunits >=3 & transac_type_abbr == "DA" & storeid == 1, unique(releaseid)] ggplot(data=DT.grid.apprvd_titles[releaseid %in% releaseid_above_3], aes(x=week_number, y=releaseid)) + geom_tile(aes(fill=paidunits)) + coord_flip() P.weekly_counts__apprvd_titles <- ggHeatColumns(DT.grid.apprvd_titles, heat="value") # f <- printToPDF(P.weekly_counts__apprvd_titles, height=40, width=20, math_fonts=FALSE) f <- plots.p("weekly_counts__apprvd_titles.pdf") pdf(file=f, width=20, height=60) print(P.weekly_counts__apprvd_titles) dev.off() .o(f) P <- ggHeatColumns(DT.weekly_avg.apprvd_titles[storeid==1 & transac_type_abbr == "DA"], id.var="releaseid", colsToPlot="royaltydollar", heat="value") print(P) DT.perc_of_weeks.apprvd_titles <- { DT.weekly_avg.apprvd_titles[storeid == 1][paidunits >= 2][,transac_type_abbr := factor(transac_type_abbr)] [order(transac_type_abbr, releaseid), wdiff := diffNA(week_number, fill=.01)*100, by=kCols.tr][, perc_of_weeks := (sum(round(wdiff) %in% c(1, 48) / .N) ) , by=kCols.tr][, list(perc_of_weeks=unique(perc_of_weeks)), keyby=kCols.tr] } ggplot(DT.perc_of_weeks.apprvd_titles, aes(x=perc_of_weeks)) + geom_bar() + facet_grid(transac_type_abbr ~ .) summary(DT.weekly_avg.apprvd_titles) gg_barChart_bygrp(DT.plot, x="week_number", y="royaltydollar", fill="group", grp="transac_type_abbr") ggBarchart2(DT.plot, x="week_number", y="royaltydollar", fill="group") formnumb(DT.counts.owned_and_tvt[storeid == 1], round=FALSE) formnumb(DT.counts.apprvd_titles[storeid == 1], round=FALSE) qMaxDate(tbl="fact_analytics", schema="production" function (input = "", sep = "auto", sep2 = "auto", nrows = -1L, header = "auto", na.strings = "NA", stringsAsFactors = FALSE, verbose = getOption("datatable.verbose"), autostart = 30L, skip = -1L, select = NULL, drop = NULL, colClasses = NULL, integer64 = getOption("datatable.integer64"), showProgress = getOption("datatable.showProgress"), data.table = getOption("datatable.fread.datatable"))