Created
February 25, 2013 23:17
-
-
Save atbradley/5034250 to your computer and use it in GitHub Desktop.
Setup to analyze playlist data from Radio Paradise, and an HTML chart function adapted from Matt Asher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
songs <- read.table('http://data.adamtbradley.com/RadioParadisePlays.txt', | |
sep='-', skip=1, quote='', strip.white=T, | |
allowEscapes=T, col.names=c('time', 'artist', 'track')) | |
songs$artist <- sub('–', '-', songs$artist) | |
songs$track <- sub('–', '-', songs$track) | |
summ <- table(paste(songs$artist, songs$track, sep=": ")) | |
summ.artists = table(songs$artist) | |
smry <- data.frame(summ) | |
colnames(smry) <- c('title', 'freq') | |
smry.artists <- data.frame(summ.artists) | |
colnames(smry.artists) <- c('title', 'freq') | |
# Created by Matt Asher for statisticsblog.com | |
# Feel free to share and modify so long as this header remains | |
# Adapted from http://tinyurl.com/abvt7el | |
HTML.chart <- function(x, maxRows=F, maxBarWidth=50, | |
tableStyle='', ytLinks=F) { | |
pTable <- x[order(x[2], decreasing=T),] | |
maxPlayed <- max(pTable[,2]) | |
toWrite <- '<table border=0 cellspacing=0 cellpadding=5>' | |
if ( !maxRows ) maxRows <- dim(pTable[1]) | |
else maxRows <- min(maxRows, dim(pTable)[1]) | |
for(m in 1:maxRows) { | |
toWrite = paste(toWrite, '<tr>') | |
toWrite = paste(toWrite, '<td align="right"><img src="http://data.adamtbradley.com/red.png" title="Played ', pTable[m,2], ' times" height=14 width=', round( (maxBarWidth * pTable[m,2])/maxPlayed), '></td>', sep="") | |
toWrite = paste(toWrite, '<td> </td>') | |
toWrite = paste(toWrite, '<td>') | |
if ( ytLinks ) toWrite = paste(toWrite, '<a href="http://www.google.com/search?q=', URLencode(paste('youtube', pTable[m,1] , sep=" ")) ,'&btnI" target="_new" title="Watch video">', sep="") | |
toWrite = paste(toWrite, pTable[m,1], "\n") | |
if ( ytLinks ) toWrite = paste(toWrite, '</a>') | |
toWrite = paste(toWrite, '</td><tr>') | |
} | |
toWrite <- paste(toWrite, '</table>') | |
toWrite | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment