GlitchMob_graph.r


lib(ggplot2)
lib(reshape2)
lib(scales)

TRACKS.MELT <- melt(TRACKS, id.vars=c("isrc", "Track"), variable.name="Metric", value.name = "value")
TRACKS.MELT <- as.data.table(TRACKS.MELT)
setkey(TRACKS.MELT, Metric, isrc)
P.Melt <- ggplot(data=TRACKS.MELT, aes(x=Track, y=value)) + theme(axis.text.x=element_text(angle=30)) + scale_y_continuous(labels=comma) + 
      geom_bar(stat="identity") + facet_grid(Metric~.)

(P.Melt <- ggplot(data=TRACKS.MELT, aes(x=Track, y=value)) + theme(axis.text.x=element_text(angle=30)) + scale_y_continuous(labels=comma) + 
      geom_bar(stat="identity", aes(fill=Metric)))

P <- ggplot(data=TRACKS.MELT, aes(x=Track)) + theme(axis.text.x=element_text(angle=30)) + 
      geom_bar(stat="identity") + facet_grid(Metric~.)


theme(panel.grid.major=element_line(linetype=2,color="black"),
        axis.text.x=element_text(angle=90,hjust=1,vjust=0))


            isrc                        Track Total_Spins_Per_Track Unique_Fans_Per_Track AVG_Total_Spins_Per_Fan AVG_Spins_of_each_Track_Per_Fan AVG_Unique_Tracks_Per_Fan
 1: QMBZ91303405              Mind of a Beast                223842                104117                 9.10700                         2.14991                   3.56557
 2: QMBZ91303406                   Our Demons                138509                 56750                 3.45668                         1.62267                   2.25142
 3: QMBZ91303407                    Skullclub                108619                 42086                 3.80000                         1.95455                   2.12727
 4: QMBZ91303408          Becoming Harmonious                 89243                 34633                 3.16667                         2.00000                   1.83333
 5: QMBZ91303409               Can''t Kill Us                 84880                 33704                 1.45406                         1.42472                   1.02015
 6: QMBZ91303410        I Need My Memory Back                 72182                 26722                 2.97059                         1.55882                   1.85294
 7: QMBZ91303411                   Skytoucher                 69115                 24189                 2.20690                         1.82759                   1.27586
 8: QMBZ91303412            Fly By Night Only                 67547                 22608                 2.44588                         1.61228                   1.64136
 9: QMBZ91303413                Carry the Sun                 57988                 19373                 2.08333                         1.58333                   1.50000
10: QMBZ91303414 Beauty of the Unhidden Heart                 51945                 17490                 1.50000                         1.50000                   1.00000
    FirstTrackPercentage FirstTrackPercentage_less_Tk1
 1:                93.96                            NA
 2:                 2.23                         36.93
 3:                 0.10                          1.64
 4:                 0.03                          0.45
 5:                 3.04                         50.45
 6:                 0.03                          0.51
 7:                 0.03                          0.43
 8:                 0.56                          9.26
 9:                 0.01                          0.18
10:                 0.01                          0.15


DT.using <- GM[sort(sample(nrow(GM), 30000))]

isrcs <- unique(DT.using[["isrc"]])

# DT.using[duration > 30, duration := as.integer(round(duration, -1))]
P.skips <- ggplot(DT.using) + geom_density(aes(x=duration, fill=track), color=0, alpha=0.3) + geom_vline(aes(x=track.length, color=track))
P.skips

.SD <- DT.using[c("QMBZ91303405", "QMBZ91303406", "QMBZ91303412")]
(P.base <- ggplot(.SD) + geom_density(aes(x=duration.perc/100, fill=track), color=0, alpha=0.3) + .nolegend + labs(title=.SD$track, x=NULL, y=NULL))
P.base + scale_x_continuous(labels=percent)
# + geom_vline(aes(xintercept=track.length, color=track))

Plots <- DT.using[, list(list(  ggplot(.SD) + geom_density(aes(x=duration.perc/100, fill=track), color=0, alpha=0.3) +.nolegend + labs(title=.SD$track, x=NULL, y=NULL) + scale_x_continuous(labels=percent)  ))
     # , by=isrc]
    , by=((as.numeric(isrc)+1) %/% 3)%%3]
Plots[1, V1]

library(gridExtra)
do.call(grid.arrange, c(Plots$V1, list(ncol=1)))

================
DT.using[, track.length, by=
      ((as.numeric(isrc)+1) %/% 3)%%3
]

================


DT.durs <- GM[GM[, .I[duration >= quantile(duration, .90)], by=track]$V1, list(isrc, duration)]
(DT.durs <- GM[GM[, .I[duration >= quantile(duration, .75)], by=track]$V1, list(duration=unique(duration)), by=isrc])

unique(DT.durs, by=c("isrc","duration"))[, list(isrc, duration)]



ggplot(DT.durs, aes(x=duration)) + geom_histogram() + facet_grid(.~track)

# DT.using[duration > 30, duration := as.integer(round(duration, -1))]
P.skips <- ggplot(DT.using) + geom_density(aes(x=round(duration, -1), fill=track), color=0, alpha=0.3)
rm(P.skips)