tayloR

I used R + audio features from Spotify + lyrics from Genius + words to analyze Taylor Swift’s music over the years.

If you know me, you probably know I love Taylor Swift. More than 10 years of listening to Swift and following her in the media has given me insight into just how deliberate she is. From coded messages in her albums’ liner notes to sharply specific lyrics, Swift fills her body of work with Easter eggs, playing into and enhancing fans’ propensity for observing things. For example, the song “The Lucky One” was No. 13 – famously Swift’s lucky number – on the Red track list; that’s something many fans would notice and appreciate, me included.

Anyway, overanalysis and Taylor Swift are two of my favorite things. The programming language R is another, so when a friend showed me Charlie Thompson’s spotifyr package, I knew Swift’s music would be the first thing I analyzed.

Spotify defines certain audio features for each track it streams. A full list of these, along with their verbal definitions, can be found on Spotify’s page for developers. The spotifyr package reduces the process of pulling data for these audio features from Spotify’s web API to just a few lines of code. I also adapted Thompson’s code from his analysis of Radiohead’s music to scrape Swift’s lyrics from Genius, and I used those in lyric and sentiment analysis.

All my R code, as well as my final dataset taylor_with_lyrics (which I assign to spotify_genius), can be found here; I’ve only included the specific code that produces each visualization in this post. Speaking of the visualizations, this DataCamp blog post was a great (and fun-to-read!) resource.

So that’s the rundown. I guess there’s only one thing left to ask now.

… R you Ready foR it?

The music

My favorite audio feature, and the one that unarguably best complements sentiment analysis, is valence, defined by Spotify as:

“A measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric), while tracks with low valence sound more negative (e.g. sad, depressed, angry).”

I used a ridgeline plot to produce an overview of valence:

spotify_genius %>% ggplot(aes(x = valence, y = ordered_albums, fill = ..x..)) +

geom_density_ridges_gradient(scale = 0.9) +

scale_fill_gradient(low = "white", high = "maroon3") +

theme_fivethirtyeight() +

theme(panel.background = element_rect(fill = "white")) +

theme(plot.background = element_rect(fill = "white")) +

xlim(0,1) +

theme(legend.position = "none")

The plot makes it pretty evident that reputation’s mean valence is the lowest by far. I think that confirms it; the old Taylor really is dead. reputation-era Swift’s music is more mellow and tempered, even when she’s undeniably happy, such as on “King Of My Heart” (valence: 0.298) and “Call It What You Want” (valence: 0.237).

Here are Swift’s albums arranged by mean valence. Note that reputation’s mean valence is about 0.1 less than the next lowest.

spotify_genius %>%

group_by(album_name) %>%

summarise(mean(valence)) %>%

arrange(desc(`mean(valence)`)) %>%

kable() %>%

kable_styling(full_width = F, position = "left") %>%

row_spec(row = 1:6, background = "#fffce4", color = "red")

And here are her top five tracks by valence. Each of her albums besides reputation is represented here. reputation’s first entry, “Look What You Made Me Do,” only comes in at No. 29.

spotify_genius %>%

select(track_name, album_name, valence) %>%

top_n(5) %>%

arrange(-valence) %>%

kable() %>%

kable_styling(full_width = F, position = "left") %>%

row_spec(row = 1:5, background = "azure", color = "deeppink")

Another thing: The ridgeline plot distributions for Speak Now and Red are bimodal i.e. each have two maxima. This feels fitting since the two are Swift’s transitional albums, with which she makes inroads into pop, Red more evidently so. (Never forget that beat drop on “I Knew You Were Trouble.”) It’s also interesting to note that neither won Album of the Year at the GRAMMYs, while the two that flank them – Fearless and 1989 – both did. It’s not unreasonable to theorize that Speak Now and Red’s scattered sounds had something to do with this.