Skip to content

Instantly share code, notes, and snippets.

@jamesthomson
Created October 22, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesthomson/cd00906527c33a7cf53606658b8716dd to your computer and use it in GitHub Desktop.
Save jamesthomson/cd00906527c33a7cf53606658b8716dd to your computer and use it in GitHub Desktop.
library(plotly)
#read in data
final<-read.csv("outputFile.txt", header=FALSE)[,-c(1,2)]
original<-read.csv("zep_tracks.csv", header=FALSE)
#join together
merged<-merge(original, final, by.x="V5", by.y="V7")
#grab key vars and fix labels
plotdata<-merged[,c("V5", "V7", "V3.x", "V21.x", "V25", "V26", "V27")]
colnames(plotdata)<-c("Track", "Track_Position", "Album", "Length", "KMeans", "BKM", "GMM")
plotdata$Album <- factor(plotdata$Album, levels = c("Led Zeppelin", "Led Zeppelin II", "Led Zeppelin III", "Led Zeppelin IV", "Houses Of The Holy", "Physical Graffiti", "Presence", "In Through The Out Door", "Coda"))
plotdata$Track_Position<-paste0("Track_", plotdata$Track_Position)
plotdata$Track_Position <- factor(plotdata$Track_Position, levels = paste0("Track_", 1:15))
#plot
plot_ly(plotdata, x = ~Album, y = ~Track_Position, text = ~Track, type = 'scatter', mode = 'markers',
size = ~Length/1000/60, color = as.factor(plotdata$KMeans), colors = brewer.pal(9,"Set1"),
marker = list(opacity = 0.8, sizemode = 'diameter', sizeref=3)) %>%
layout(title = 'Led Zeppelin Tracks',
xaxis = list(showgrid = FALSE, showticklabels=TRUE, title="", type = "category"),
yaxis = list(showgrid = FALSE, showticklabels=FALSE, title="", type = "category"),
showlegend = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment