![]() Mutate ( Percentage = Percentage / sum ( Percentage ) * 100, mode_clean = recode ( mode_clean, 'maj' = 'Major', 'min' = 'Minor' )) %>% # pass to ggplot Summarise ( Percentage = n ()) %>% # calculate the % of songs per mode Raw_data %>% select ( genre_clean, mode_clean ) %>% group_by ( mode_clean ) %>% # counts of songs per mode ![]() We can make a barplot of the distribution of major and minor modes like so: # barplot of mode across songs In this analysis, we will include all of the 8,503 songs across all of the genres. A simple heuristic we can use for the present discussion is that major modes sound happy and upbeat, whereas minor modes sound sad and dark. There’s lots to say about major and minor modes, and if you’re interested in learning more this Wikipedia page is a good place to start. The mode is a property that describes the tonal base of a song. Let’s first take a look at the mode of the songs. What most of these songs have in common is that they are primarily guitar-driven. It must be noted that “rock” is somewhat of a catch-all genre, encompassing many different sub-categories. This matches my intuition - it’s definitely the type of music that I listen to. The top three genres are rock (3,426 songs), rap (1,411 songs) and jazz (1,141 songs). Raw_data %>% group_by ( genre_clean ) %>% summarise ( num_songs = n ()) %>% ggplot ( aes ( x = reorder ( genre_clean, num_songs ), y = num_songs, fill = genre_clean )) + geom_bar ( stat = 'identity' ) + geom_text ( aes ( label = num_songs ), size = 4, hjust = -0.15 ) + coord_flip ( ylim = c ( 0, 3500 )) + labs ( x = "Genre", y = "Number of Songs", title = 'Number of Songs Per Genre' ) + theme ( legend.position = "none" ) Library ( plyr ) library ( dplyr ) library ( ggplot2 ) library ( tidyverse ) library ( gplots ) library ( RColorBrewer ) library ( kableExtra ) # barplot of song counts per genre We will look at the overall properties of the songs across all of our data, and we will also see how these musical qualities differ across genres.Īs a first step in this process, let’s take a look at the frequency of the genres in our data set: # load the libraries we'll need In this blog post, we are interested in the musical properties of the songs in my music collection. There are 8,503 songs in the cleaned dataset. I’ve concatenated the mode and the key to create a variable called master_key, which contains the complete song key information. For each song, we have the mode and the key as determined by Spotify. The head of the raw data looks like this:įor each album, we have the album name and genre, artist, as well as the names of each song. The data and code for this analysis are available on Github here. In total, I was able to retrieve the mode and key information for about 80% of the albums in my digital collection (obscure or niche recordings are not always available on Spotify). I queried the Spotify API using Python and the excellent Spotipy package. I then used the artist and album information to get the song mode and key for each album track from the Spotify API, which has catalogued this information for a huge number of albums. I have most of the music I’ve listened to over the past 10 years in a digital format, and I extracted the artist, album, and musical genre information from ID3 tags included in the files (using code adapted from a previous blog post). ![]() The data for this blog post come from the digital music (.mp3) files on my computer. ![]() Finally, we’ll explore differences across genres in the modes and keys that the music is played in, and use this information to simultaneously cluster the musical keys and genres. whether the songs are played in major or minor keys), and the musical key itself (e.g. We will focus on two primary aspects of the music: the mode (e.g. In this post, we will examine the harmonic properties of songs in my music collection. ![]()
0 Comments
Leave a Reply. |