‘Rock’ing Analysis in R

Extracting insights from the data of top 500 music albums of all time.

satyaprakash pareek
The CodeHub
5 min readMay 19, 2020

--

Photo by Kelly Sikkema on Unsplash

Rolling Stones’ list of top 500 Albums is considered by many as the compilation of best music ever. As a beginner in R, I started to look at this dataset with the help of Rahul and Rishi Sidhu.

Let us look at the dataset and see what insights we can get from it.

The dataset has 500 rows and 6 columns. The dataset looks like this:

We have top 500 albums with their ranks (Number), Artists and Genres. Let us first analyze year-wise distribution to understand which is/was the golden era of music.

We can see that 70’s was the golden era of music. We could also populate the bars for each year with each genre or artist. Note the use of ‘fill’ argument in the aesthetic.

We can see that Rock (pink color) was the predominant genre in 70's

Now let’s try to find the most successful artist in this list. Success can be subjective. So you could find any metric to define it. For the sake of simplicity, I will focus on the top 100 albums only. Smaller the ‘Number’, better the rank of the album. Another important parameter of success could number of times an artist is featured in top 100.

In the above code,

  • mutate creates a new column Number_thre which takes a value of 0 if Number is greater than 100, else it is 100 — Number.
  • filter function keeps only those rows for which Number_thre > 0 i.e. album rank is above 100.
  • Finally, we group the dataframe by Artist and then calculate a new field Number_of_Features in top 100.

If you are new to use of piping (%>%) in R, here is a very informative article.

This is how the resulting dataframe looks:

Looking at the dataframe, we can see that there are a lot of artists which are featured only once in the top-100 while there are some which have repeated features. For finding most successful artists, we only keep artists with 1 or more features. A simple way of ranking the artists can be taking mean of their Ranks which we just calculated.

Artists ranked by our ranking algorithm

To see this visually, let’s plot it.

Now let’s see how versatility of an artist correlates with their success. We can define versatility as the number of genres they have explored. Within the limits of this dataset, let’s explore this:

First, we will separate genre and subgenre columns in the original dataframe into a number of genres. This can be achieved using separate function as seen previously. We want to get this data in long format, as we want to count the number of genres for each artist. Learn more on pivoting in this article.

Now we can group by Artist and count distinct genres. Multiple albums can have same genre and hence we need to find distinct genres.

Now we have list of Artists and Number of genres. Previously, we created another dataframe d_ranked which had list of artists and their ranking. Let’s join the two data frames. Function inner_join takes two dataframes and joins them based on common key Artist. Let us also see how the joined dataframe looks.

First 6 rows of joined dataframe

Now let’s plot this data to visually see this correlation. Some point to note are: we want to plot a dot (point) graph and we want the size of dots proportional to ranking. We would like to annotate the dots with names of artists: geom_label_repel in ggrepel package provides a clean way to do that.

We can do a lot of more with this dataset. To see, which artists rocked decadewise or which artists succeeded for many decades. If you are interested in this analysis, feel free to reach out for the code. Have fun with R.

Thanks to Rahul and AI Graduate Admin for helping me learn this. For more fun assignments in R, do follow this Github repo made by Rahul.

--

--