Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created April 11, 2018 20:12
Show Gist options
  • Select an option

  • Save MattSandy/1272e4e3d01fe4f61a45e76e601a426b to your computer and use it in GitHub Desktop.

Select an option

Save MattSandy/1272e4e3d01fe4f61a45e76e601a426b to your computer and use it in GitHub Desktop.
Taylor Swift Alcohol References
library("stringr")
ts <- stream_in(file("log.json"))
alcohol <- c("bar","beer","champagne","drink","drunk","liquir","whiskey","wine","champaign","whisky","liquor")
melt <- matrix(NA,nrow=0,ncol=2)
for(ref in alcohol) {
for(track in ts$title[grep(ref,ts$lyrics,ignore.case = T)]) {
for(i in 1:str_count(ts$lyrics[which(ts$title==track)],ref)) {
melt <- rbind(melt,c(track,ref))
}
}
}
melt <- data.frame(melt,stringsAsFactors = F)
names(melt) <- c("Track","Reference")
melt <- melt[order(melt$Track),]
g <- ggplot(melt, aes(Track))
g + geom_bar(aes(fill = Reference), position = position_stack(reverse = TRUE)) +
coord_flip() + theme_bw() + theme(panel.grid = element_blank(), panel.border = element_blank()) +
theme(legend.position = "top", legend.direction = "horizontal") + scale_fill_tableau() +
theme(axis.text.y = element_text(angle=0,margin = margin(t = 0, r = -40, b = 0, l = 0)),
axis.ticks.y = element_blank(),
plot.title = element_text(hjust = 0.5)) + ggtitle("Taylor Swift - Reputation") +
guides(fill=guide_legend(nrow=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment