Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
Add Comment
Please, Sign In to add comment