How does music change over time?

visualization spotify

Visualize the differing trends in volume, tempo, energy, and popularity over time.

Wanjia Guo https://wanjiag.github.io/
03-05-2021

Data Cleaning

data1 = data %>% 
  select(id, popularity, year, danceability, duration_ms, tempo, speechiness) %>% 
  mutate(popularity = (popularity-min(popularity))/(max(popularity)-min(popularity)),
         danceability = (danceability-min(danceability))/(max(danceability)-min(danceability)),
         duration = 
           (duration_ms-min(duration_ms))/(max(duration_ms)-min(duration_ms)),
         tempo = (tempo-min(tempo))/(max(tempo)-min(tempo)),
         speechiness = (speechiness-min(speechiness))/(max(speechiness)-min(speechiness))) %>% 
  select(-duration_ms)
  

fig1_data = data1 %>% select(-year) %>% 
  mutate(danceability = cut(danceability, 100, labels=FALSE),
         duration = cut(duration, 100, labels=FALSE),
         tempo = cut(tempo, 100, labels=FALSE),
         speechiness = cut(speechiness, 100, labels=FALSE)) %>% 
  pivot_longer(cols = danceability:duration, 
               names_to = "property") %>% 
  group_by(property, value) %>% 
  summarise(popularity_median = median(popularity)) %>% 
  mutate(property = factor(property, levels=c("danceability",
                                              "tempo",
                                              "speechiness",
                                              "duration"),
                           labels = c("Danceability",
                                              "Tempo",
                                              "Speechiness",
                                              "Duration")))

fig2_data = data1 %>% 
  mutate(decades = year - year %% 10 ) %>% 
  select(-c(popularity, year)) %>% 
  pivot_longer(cols = danceability:duration, 
               names_to = "property") %>% 
  group_by(property, decades) %>% 
  summarise(mean = mean(value)) %>% 
  mutate(property = factor(property, levels=c("duration",
                                              "speechiness",
                                              "tempo",
                                              "danceability")))
fig2_data2 = data_by_year %>% 
  select(-c(key, mode)) %>% 
  mutate(acousticness = (acousticness-min(acousticness))/(max(acousticness)-min(acousticness)),
         danceability = (danceability-min(danceability))/(max(danceability)-min(danceability)),
         duration = (duration_ms-min(duration_ms))/(max(duration_ms)-min(duration_ms)),
         energy = (energy-min(energy))/(max(energy)-min(energy)),
         instrumentalness =
           (instrumentalness-min(instrumentalness))/(max(instrumentalness)-min(instrumentalness)),
         liveness = (liveness-min(liveness))/(max(liveness)-min(liveness)),
         loudness = (loudness-min(loudness))/(max(loudness)-min(loudness)),
         speechiness = (speechiness-min(speechiness))/(max(speechiness)-min(speechiness)),
         tempo = (tempo-min(tempo))/(max(tempo)-min(tempo)),
         valence = (valence-min(valence))/(max(valence)-min(valence)),
         popularity = (popularity-min(popularity))/(max(popularity)-min(popularity))
         ) %>% 
  select(-duration_ms) %>% 
  pivot_longer(cols = acousticness:duration, 
               names_to = "property")

fig2_data3 = fig2_data2 %>% 
  filter(property %in% c('energy', 'loudness', 'tempo', 'popularity')) %>% 
  mutate(property = factor(property, levels=c('popularity','energy', 'loudness', 'tempo')))

Final Visualization

ggplot(fig2_data3 %>% 
         filter(property!="popularity"),
       aes(x=year, y=value)) + 
  geom_line(aes(color=property)) +
  geom_line(data=fig2_data3 %>% 
              filter(property=="popularity"), 
            aes(x=year, y=value), 
            color="red",
            size=1.3)+
  gghighlight(use_direct_label = FALSE)+
  scale_color_OkabeIto(darken=-0.5)+
  theme(plot.title = ggtext::element_markdown(),
        legend.position = "none",
        axis.title.x=element_blank())+
  labs(title = "Music is 
  <span style = 'color: #57B4E9'>louder</span> 
  <span style = 'color: #029E73'>higher tempo</span> 
  <span style = 'color: #E69F00'>more energetic</span>,\n
  but NOT
  <span style = 'color: #FF2500'>**more popular**</span>",
  y = "Normalized Scores (0-1)")

My personal favorite part of this figure is the fact that it tells a good story. There are a lot properties I could choose to plot, but it is only interesting when there are contrasts. It is interesting (to me personally) to realize that since 2000, despite the fact that the songs are loud, high tempo, and energtic, they are only dropping in popularity.

Attempt 1

ggplot(fig2_data, aes(x=decades, y=property, fill=mean)) + geom_tile() +
  scale_fill_viridis_c(option = "A") + 
  labs(y="Property", x="Decade") + 
  theme(legend.position = "top")

This is not bad, but also not great. I think the suggestion that I received the most is to rank the property based on the color, so I did that. However, I still feel because I calculated the mean of song’s property, though I normalized scores, the range of each property is still very different, which makes the change within some properties impossible to see.

Attempt 2

ggplot(fig2_data2, aes(x=year, y=value)) + 
  geom_line(aes(color=property)) +
  gghighlight(use_direct_label = FALSE)+
  facet_wrap(~property)+
  theme(legend.position = "none")

I realized there is another dataset that is already ranked by year, so I thought I would try to clean that dataset and see if that works better. I also take a look at a lot more properties just to see what properties changes more or are more interesting. I end up thinking I should try to take in the characteristics that are interesting and tell a story. E.g. I found 3 increasing (energy, loudness, tempo) properties as well as 3 decreasing (acousticness, instrumentalness, speechiness) pnes. Popularity and duration are something that people are generally interested in as well.

Citation

For attribution, please cite this work as

Guo (2021, March 5). Visualizing Spotify: How does music change over time?. Retrieved from https://wanjiag.github.io/EDLD652_project_blog/posts/2021-03-05-how-does-music-change-over-time/

BibTeX citation

@misc{guo2021how,
  author = {Guo, Wanjia},
  title = {Visualizing Spotify: How does music change over time?},
  url = {https://wanjiag.github.io/EDLD652_project_blog/posts/2021-03-05-how-does-music-change-over-time/},
  year = {2021}
}