Skip to content

Instantly share code, notes, and snippets.

@cavedave
Last active July 16, 2017 17:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cavedave/572a3c6f8ab6333343c727ccc5f0e656 to your computer and use it in GitHub Desktop.
Save cavedave/572a3c6f8ab6333343c727ccc5f0e656 to your computer and use it in GitHub Desktop.
#data from http://www.modestinsights.com/analyzing-the-billboard-hot-100/ 'Instead I’ve uploaded all the raw data here, in PSV format '
#library used is ggjoy from https://github.com/clauswilke/ggjoy
data<-read.csv("all_billboard_data.csv", header=TRUE, sep="\t")#this is the psv where ive swapped \| for \t. I probably didnt need to.
library(lubridate)
library(devtools)
install_github("clauswilke/ggjoy")
library(ggplot2)
library(ggjoy)
#get the date into a year and then a decade
a=ymd(data$chart.date)
b=year(a)
data["when"] <- b
data2<-data[complete.cases(data), ]#remove rows with missing columns
data2["decade"] <- data2["when"] - (data2["when"]%% 10)#make a column where the decade is stored
data2$weeks.on.chart[data2$weeks.on.chart>40] <- 40 #make those rare singles on for over 40 weeks = 40 for graphing reasons
ggplot(data2, aes(x = weeks.on.chart, y = decade, group = decade))+
geom_joy2()+
labs(title = 'Songs Time on Billboard Top 100',subtitle='https://gist.github.com/cavedave/',
x="Weeks",y="")+
scale_x_continuous(limits=c(1, 40), expand = c(0.01, 0)) +
scale_y_reverse(breaks=c(2000, 1980, 1960, 1940, 1920, 1900), expand = c(0.01, 0))+
theme_joy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment