Music listener statistics: last.fms last.year as an R package

When starting analyzing scrobbles with the last.week and last.year function I was always missing some plots or a pure data table. That is why I developed the package analyzelastfm as a simple R6 implementation. I wanted to have different album statistics, as e.g the #of plays per album, divided by the # of tracks on the album. This is now implemented. To get music listening statistic you would start with:

# If you don't have it, install devtools
# install.packages("devtools")

First it allows you to import yourlast.yeardata by using the REST API. Therefore you need to have a API key. This can be derived by simply going to API website. From there you will get the 32 character long key. After receiving the key I got my data by:

data <- UserData$new("zappingseb",api_key,2018)

The data object now contains the functionalbumstatsthat allows me to get the specific information I wanted. Ill exclude the artist Die drei??? as its a kids detective story from Germany I listen to a lot and whichs albums are split into 1 minute tracks, that really screws up my statistic.

  sort_by="by_album_count", # album track plays / nr tracks on album
  exclude_artist="Die drei ???", # exclude my audio book favorite
  exclude_album=c(""), # exclude tracks without album name
  min_tracks=5) # have minimum 5 tracks on the album (NO EPs)

The result looks like that:

Album statistics of 2018 of zappingseb

The statistic shows n the number of plays, count the number of tracks on the album and count_by_track=n/count .

The top 5 albums you can find here:

Additionally to such calculations, I was also interested in when I was listening to music. Therefore I added some plots to the package. The first one is the listening clock:

Clock plot for my music history

I listen to music mostly on my way to work on the bike between 7 and 8 am and between 5 and 6 pm. My most important statistic though is which time of the year I spent listening to music. Im most interested in some specific days and an average play/month, that can tell me in which mood I was in. Therefore I created the functiondaily_month_plot. It plots the average plays per month and the daily plays in one plot. The average plays per month are visualized behind the daily spikes. Here you can see that February was a really quiet month for me.


For some simple statistics, I also included an aggregation plotting function called barplots . It can plot aggregations per weekday, week, month or day. The data for this function is provided by the function bar_data .


weekly (starting with week 52 of 2017):


Where I can clearly see that I was not really listening to a lot of music during the beginning of the year and my listening activity increased dramatically by week 18.

This post is a bit out of my spectrum, which mostly deals with packages about R packages being useful for Pharma. But I really like music and think music and data science make a good combination. Sounds great together!

Please find the R package at: too late to star it 😉