Photo on musikalessons.com

Wrangling and Visualizing Music Data

Photo on musikalessons.com

Wrangling and Visualizing Music Data

Introduction

How do musicians choose the chords they use in their songs? Do guitarists, pianists, and singers gravitate towards different kinds of harmony?

We can uncover trends in the kinds of chord progressions used by popular artists by analyzing the harmonic data provided in the McGill Billboard Dataset. This dataset includes professionally tagged chords for several hundred pop/rock songs representative of singles that made the Billboard Hot 100 list between 1958 and 1991. Using the data-wrangling tools available in the dplyr package, and the visualization tools available in the ggplot2 package, we can explore the most common chords and chord progressions in these songs, and contrast the harmonies of some guitar-led and piano-led artists to see where the “affordances” of those instruments may affect the chord choices artists make.

# Loading the tidyverse meta-package
library(tidyverse)

# Reading in the McGill Billboard chord data
bb <- read_csv('datasets/bb_chords.csv')

# Taking a look at the first rows in bb
head(bb, 1)
year chord root_integer root_roman quality title_compressed artist_compressed title artist
1961 A:min 9 VI min idon’tmind jamesbrown I Don’t Mind James Brown

The most common chords

As seen above, in this dataset: each row represents a single observation, and each column a particular variable or attribute of that observation. Note that the metadata for each song (title, artist, year) is repeated for each chord – like “I Don’t Mind” by James Brown, 1961 – while the unique attributes of each chord (chord symbol, chord quality, and analytical designations like integer and Roman-numeral notation) is included once for each chord change.

A key element of the style of any popular musical artist is the kind of chords they use in their songs. But not all chords are created equal! In addition to differences in how they sound, some chords are simply easier to play than others. On top of that, some chords are easier to play on one instrument than they are on another. And while master musicians can play a wide variety of chords and progressions with ease, it’s not a stretch to think that even the best musicians may choose more “idiomatic” chords and progressions for their instrument.

To start to explore that, let’s look at the most common chords in the McGill Billboard Dataset.

# Counting the most common chords
bb_count <- bb %>% count(chord) %>% arrange(desc(n))

# Displaying the top 20 chords
head(bb_count, 20)
chord n
C:maj 1183
G:maj 1140
A:maj 1071
D:maj 1054
F:maj 859
E:maj 839
Bb:maj 718
B:maj 503
Ab:maj 375
Eb:maj 360
A:min 328
E:min 298
Db:maj 293
D:min 250
B:min 236
N 201
E:min7 186
C:min 176
D:7 176
A:min7 170

Visualizing the most common chords

Of course, it’s easier to get a feel for just how common some of these chords are if we graph them and show the percentage of the total chord count represented by each chord. Musicians may notice right away that the most common chords in this corpus are chords that are easy to play on both the guitar and the piano: C, G, A, and D major — and to an extent, F and E major. (They also belong to keys, or scales, that are easy to play on most instruments, so they fit well with melodies and solos, as well.) After that, there is a steep drop off in the frequency with which individual chords appear.

# Creating a column plot from `bb_bigram_count`
bb_bigram_count %>% slice(1:20) %>%
  mutate(share = n/sum(n),
         bigram = reorder(bigram, share)) %>%
  ggplot(aes(x = bigram, y = share)) + geom_bar(stat = "identity", alpha = 0.6, fill = 'black') +
  coord_flip() +
  xlab("Share of total Chords") +
  ylab("Bigram") + theme_bw()

Chord “bigrams”

Just as some chords are more common and more idiomatic than others, not all chord progressions are created equal. To look for common patterns in the structuring of chord progressions, we can use many of the same modes of analysis used in text-mining to analyze phrases. A chord change is simply a bigram — a two-“word” phrase — composed of a starting chord and a following chord. Here are the most common two-chord “phrases” in the McGill Billboard dataset.

# Wrangling and counting bigrams
bb_bigram_count <- bb %>%
    mutate(next_chord = lead(chord, 1), next_title = lead(title, 1)) %>% 
mutate(bigram = str_c(chord, next_chord, sep = " ")) %>% filter(title == next_title) %>%
group_by(bigram) %>% 
    summarize(n = n()) %>% 
    arrange(desc(n))

# Displaying the first 20 rows of bb_bigram_count
head(bb_bigram_count, 20)
bigram n
G:maj D:maj 241
C:maj F:maj 234
C:maj G:maj 217
B:maj E:maj 202
F:maj C:maj 195
A:maj E:maj 190
A:maj D:maj 189
D:maj G:maj 185
G:maj C:maj 185
D:maj A:maj 179
E:maj A:maj 175
F:maj Bb:maj 143
Bb:maj F:maj 134
E:maj B:maj 134
Bb:maj C:maj 133
G:maj A:maj 133
A:maj B:maj 112
A:maj G:maj 105
F:maj G:maj 99
D:maj C:maj 93

Visualizing the most common chord progressions

We can get a better sense of just how popular some of these chord progressions are if we plot them on a bar graph. Note how the most common chord change, G major to D major, occurs more than twice as often than even some of the other top 20 chord bigrams.

# Creating a column plot from `bb_bigram_count`
bb_bigram_count %>% slice(1:20) %>%
  mutate(share = n/sum(n),
         bigram = reorder(bigram, share)) %>%
  ggplot(aes(x = bigram, y = share)) + geom_bar(stat = "identity", alpha = 0.6, fill = 'black') +
  coord_flip() +
  xlab("Share of total Chords") +
  ylab("Bigram") + theme_bw()

Finding the most common artists

As noted above, the most common chords (and chord bigrams) are those that are easy to play on both the guitar and the piano. If the degree to which these chords are idiomatic on guitar or piano (or both) determine how common they are, we would expect to find the more idiomatic guitar chords (C, G, D, A, and E major) to be more common in guitar-driven songs, but we would expect the more idiomatic piano chords (C, F, G, D, and B-flat major) to be more common in piano-driven songs. (Note that there is some overlap between these two instruments.)

The McGill Billboard dataset does not come with songs tagged as “piano-driven” or “guitar-driven,” so to test this hypothesis, we’ll have to do that manually. Rather than make this determination for every song in the corpus, let’s focus on just a few to see if the hypothesis has some validity. If so, then we can think about tagging more artists in the corpus and testing the hypothesis more exhaustively.

Here are the 20 artists with the most songs in the corpus. From this list, we’ll extract a few artists who are obviously heavy on guitar or piano to compare.


# Finding and displaying the 20 artists with the most songs in the corpus
bb_30_artists <- bb %>% select(artist, title)  %>%
    unique() %>% count(artist) %>% arrange(desc(n))

bb_30_artists %>%
  slice(1:20)
artist n
Elvis Presley 13
Brenda Lee 9
Dion 8
Bob Seger 7
James Brown 7
Kenny Rogers 7
The Beatles 7
Chicago 6
Dr. Hook 6
Eric Clapton 6
John Denver 6
Johnny Tillotson 6
The Beach Boys 6
Abba 5
Billy Idol 5
Cliff Richard 5
Glen Campbell 5
The Rolling Stones 5
Billy Joel 4
Cheap Trick 4

Tagging the corpus

There are relatively few artists in this list whose music is demonstrably “piano-driven,” but we can identify a few that generally emphasize keyboards over guitar: Abba, Billy Joel, Elton John, and Stevie Wonder — totaling 17 songs in the corpus. There are many guitar-centered artists in this list, so for our test, we’ll focus on three well known, guitar-heavy artists with a similar number of songs in the corpus: The Rolling Stones, The Beatles, and Eric Clapton (18 songs).

Once we’ve subset the corpus to only songs by these seven artists and applied the “piano” and “guitar” tags, we can compare the chord content of piano-driven and guitar-driven songs.

tags <- tibble(
  artist = c('Abba', 'Billy Joel', 'Elton John', 'Stevie Wonder', 'The Rolling Stones', 'The Beatles', 'Eric Clapton'),
  instrument = c('piano', 'piano', 'piano', 'piano', 'guitar', 'guitar', 'guitar'))

# Creating a new dataframe `bb_tagged` that includes a new column `instrument` from `tags`
bb_tagged <- bb %>%
     inner_join(tags)
    
# Displaying the new dataframe
bb_tagged
year chord root_integer root_roman quality title_compressed artist_compressed title artist instrument
1984 C:maj 0 I maj aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 D:min 2 II min aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 F:maj 5 IV maj aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 G:maj 7 V maj aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 C:maj 0 I maj aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 D:min 2 II min aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 F:maj 5 IV maj aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 G:maj 7 V maj aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 C:maj 0 I maj aninnocentman billyjoel An Innocent Man Billy Joel piano
1984 G:min7 7 V min7 aninnocentman billyjoel An Innocent Man Billy Joel piano

Comparing chords in piano-driven and guitar-driven songs

Let’s take a look at any difference in how common chords are in these two song groups. To clean things up, we’ll just focus on the 20 chords most common in the McGill Billboard dataset overall.

While we want to be careful about drawing any conclusions from such a small set of songs, we can see that the chords easiest to play on the guitar do dominate the guitar-driven songs, especially G, D, E, and C major, as well as A major and minor. Similarly, “flat” chords (B-flat, E-flat, A-flat major) occur frequently in piano-driven songs, though they are nearly absent from the guitar-driven songs. In fact, the first and fourth most frequent piano chords are “flat” chords that occur rarely, if at all, in the guitar songs.

So with all the appropriate caveats, it seems like the instrument-based-harmony hypothesis does have some merit and is worth further examination.

# The top 20 most common chords
top_20 <- bb_count$chord[1:20]

# Comparing the frequency of the 20 most common chords in piano- and guitar-driven songs
bb_tagged %>%
  filter(chord == top_20) %>%
  count(chord) %>% arrange(desc(n)) %>%
  ggplot(aes(x = chord, y = n)) + geom_bar(stat = 'identity') + 
  coord_flip() +
  xlab("Chord") +
  ylab("Count of each chord")

Comparing chord bigrams in piano-driven and guitar-driven songs

Since chord occurrence and chord bigram occurrence are naturally strongly tied to each other, it would not be a reach to expect that a difference in chord frequency would be reflected in a difference in chord bigram frequency. Indeed that is what we find.

# The top 20 most common bigrams
top_20_bigram <- bb_bigram_count$bigram[1:20]

# Creating a faceted plot comparing guitar- and piano-driven songs for bigram frequency
bb_tagged %>%
  filter(chord %in% top_20) %>%
    group_by(chord, instrument) %>% 
    summarize(n = n()) %>% 
    ggplot(aes(x = chord, y = n)) +
    geom_bar(stat = 'identity') +
    coord_flip() +
    facet_grid(~instrument) +
    xlab("Chord") +
    ylab("Freq")


# Displaying the first 20 rows of bb_bigram_count
head(bb_bigram_count, 20)
bigram n
G:maj D:maj 241
C:maj F:maj 234
C:maj G:maj 217
B:maj E:maj 202
F:maj C:maj 195
A:maj E:maj 190
A:maj D:maj 189
D:maj G:maj 185
G:maj C:maj 185
D:maj A:maj 179
E:maj A:maj 175
F:maj Bb:maj 143
Bb:maj F:maj 134
E:maj B:maj 134
Bb:maj C:maj 133
G:maj A:maj 133
A:maj B:maj 112
A:maj G:maj 105
F:maj G:maj 99
D:maj C:maj 93

Conclusion

We set out asking if the degree to which a chord is “idiomatic” on an instrument affects how frequently it is used by a songwriter. It seems that is indeed the case. In a large representative sample of pop/rock songs from the historical Billboard charts, the chords most often learned first by guitarists and pianists are the most common. In fact, chords commonly deemed easy or beginner-friendly on both piano and guitar are far and away the most common in the corpus.

We also examined a subset of 35 songs from seven piano- and guitar-heavy artists and found that guitarists and pianists tend to use different sets of chords for their songs. This was an extremely small (and likely not representative) sample, so we can do nothing more than hypothesize that this trend might carry over throughout the larger dataset. But it seems from this exploration that it’s worth a closer look.

Avatar
Amol Kulkarni
Ph.D.

My research interests include application of Machine learning algorithms to the fields of Marketing and Supply Chain Engineering, Decision Theory and Process Optimization.