

otherGenres <- c("Children's", "Latin Music", "Spoken Word", "World Music", 
                  "Blues", "Classical", "R&B", "Soundtracks", "Jazz", "New Age")

DT.Plot <- copy(DB.SpotifyMeta.Long[!is.na(ctr)& Week=="Wk1plusWk2"])
DT.Plot[genre %in% otherGenres, genre := "OTHER"]
DT.Plot[, genre := genreClean[genre]]
DT.Plot[, artist := factor(artist)]
DT.Plot[, artist := setFactorOrder(artist, rev(levels(artist)))]
DT.Plot[, c("xinter", "goodbad") := list(factor(NA, levels=levels(artist)), 0L)]
m.ctr <- DT.Plot[, mean(ctr)]
sd.m  <- DT.Plot[, sd(ctr)]
DT.Plot[ctr > m.ctr + 1.85 * sd(ctr), c("xinter", "goodbad") := list(artist, 1L)]
DT.Plot[ctr < m.ctr - 1.85 * sd(ctr), c("xinter", "goodbad") := list(artist, -1L)]
DT.Plot[, textlabel := center(artist, align=c("left", "center", "right")[[goodbad+2]]), by=goodbad]

P <- 
ggplot(DT.Plot, aes(x=artist, y=ctr, color=genre, size=1-PercOfStreamsAdSupptd, label=artist)) + 
   geom_point() + 
#   scale_y_log10() + 
   geom_hline(yintercept=m.ctr, color="purple", alpha=0.5) + 
   geom_hline(yintercept=m.ctr + DT.Plot[, c(-2, 2)*sd(ctr)], color="purple", alpha=0.7) + 
   theme(axis.text=element_text(size=rel(0.35), angle=10)) + 
   geom_vline(xintercept=DT.Plot[ goodbad > 0, as.numeric(xinter)], color="green", alpha=0.35) +
   geom_vline(xintercept=DT.Plot[ goodbad < 0, as.numeric(xinter)], color="red", alpha=0.35) +
   labs(size="% of Non-Add Suppt'd Streams", y="CTR", x="Campaign", title="Spotify Add Campaigns\nCTR by Genre") +
   coord_flip() 


P <- P + geom_text(data=DT.Plot[!is.na(xinter), list(artist=as.numeric(xinter), ctr=ctr + (.75 * sd.m * -goodbad), genre, PercOfStreamsAdSupptd, textlabel)], aes(label=textlabel), size=rel(2.35), alpha=0.7,  hjust=0.7) + scale_y_log10()
  # + scale_color_manual(values=colors.genre)

p.out <- as.path(outDir, "Plots", "SpotifyAdds_CTR_byGenre.pdf")
dir.create(dirname(p.out), showWarnings=FALSE, recursive=TRUE)

ggsave(filename=p.out, plot=P, width=11, height=11)

