Created
March 16, 2017 09:52
-
-
Save sneakers-the-rat/e711c35d25201411478a74f885652933 to your computer and use it in GitHub Desktop.
artist-frequency-raster
This file contains hidden or 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
require(stats) | |
require(ggplot2) | |
# Download your last.fm history as a .csv from here: | |
# https://benjaminbenben.com/lastfm-to-csv/ | |
# load 'em | |
lfmdat <- read.csv('~/lastfm.csv', header = FALSE) | |
names(lfmdat) <- c("artist", "album", "song", "time") | |
# clean blanks like a damn animal | |
lfmdat <- lfmdat[lfmdat[,]$artist != "",] | |
lfmdat <- lfmdat[lfmdat[,]$album != "",] | |
lfmdat <- lfmdat[lfmdat[,]$song != "",] | |
lfmdat <- lfmdat[lfmdat[,]$time != "",] | |
# Format the timestamps, see ?strptime | |
lfmdat$time <- strptime(lfmdat$time, format = "%d %b %Y %R") | |
# Assume the artists/albums are well formed and factorize | |
lfmdat$artist <- as.factor(lfmdat$artist) | |
lfmdat$album <- as.factor(lfmdat$album) | |
##### | |
# Frequency raster plot | |
# order artist factor by frequency | |
ftab = table(lfmdat$artist) | |
# pretty janky and slow but stfu | |
lfmdat$freq <- 0 | |
for (a in names(ftab)){ | |
lfmdat[lfmdat$artist == a,]$freq <- ftab[a] | |
} | |
lfmdat$artist <- factor(lfmdat$artist, levels=lfmdat$artist[order(lfmdat$freq)], ordered=TRUE) | |
# now plot that shit | |
g <- ggplot(lfmdat, aes(x=time, y=artist))+ | |
geom_point(size=0.05)+ | |
scale_x_datetime(date_breaks = "1 month", date_labels = "%m-%y")+ | |
theme( | |
axis.text.y = element_blank(), | |
axis.title.y = element_blank(), | |
axis.ticks.y = element_blank(), | |
axis.title.x = element_blank(), | |
axis.ticks.x = element_blank(), | |
panel.grid.major = element_blank(), | |
panel.grid.minor = element_blank(), | |
panel.background = element_blank(), | |
legend.position = "none", | |
axis.text.x = element_text(angle=90, hjust = 1)) | |
dir.create("~/wastin_ur_harddrive") | |
ggsave(paste("~/wastin_ur_harddrive/on_this_stupid_shit_at_",as.numeric(as.POSIXct(Sys.time())),".png",sep=""), | |
plot=g, device="png", width=4, height=7, units="in", dpi=500, bg="transparent") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment