# Load any R Packages you may need
library(tidyverse)
library(dplyr)
library(fivethirtyeight)
library(ggplot2)
spotify_songs <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-21/spotify_songs.csv')
view(spotify_songs)
Millions of songs currently exist in a wide range of streaming platforms, but there are some that are just more popular than others. It is crazy to think that despite people having unique music taste from one another, there are songs that people agree, are just really good. This means that there have to be specific features to music that make people enjoy certain songs more than others. The Spotify Songs data set from TidyTuesday, explores about 5000 songs from 6 different genres; EDM, Latin, Pop, R&B, Rap, and Rock. As well as their different audio features like loudness, tempo, energy, danceability…etc. With this data, we can see what genres are more popular and the audio features that play into their popularity.
We looked at the different genres of music in the data set to see which was most popular. The highest median of popularity was pop and lowest median was EDM. But what exactly makes those genres more popular than the others? We then looked to see how the feature danceability plays a role in popularity, and discovered that pop had a large amount of high danceability scores compared to rock which had a large amount of low danceability scores. By looking at how danceability plays a role in the popularity of a song, we can see that in general, songs with higher danceability scores are more popular.
Song Popularity Based on Genre
ggplot(spotify_songs, mapping = aes(x = playlist_genre, y = track_popularity, fill = playlist_genre ) ) +
geom_boxplot(alpha = 0.5) +
theme_minimal() +
theme(legend.position = "none", plot.title=element_text(hjust=0.5)) +
labs(x = "Genre", y = "Song Popularity (0-100)", title = "Song Popularity Based on Genre")

Here, we can view the distribution of song popularity based on genre. Each boxplot represents a different genre of music, with the dark black line in the middle indicating the median song popularity rating. The playlist_genre is mapped to the x axis, the track_popularity is mapped to the y axis, and the playlist_genre is also mapped to fill the boxplots (so that each genre corresponds to it’s own color). The colors for each genre are consistent throughout the blog, making it easier to follow.
Although the six genres have relatively close medians and distributions, we can see that the EDM genre has the lowest, and the pop and latin have the highest median popularity respectively.
With this information, let’s look at one specific audio feature, danceability, and it’s distribution among the different genres. Danceability describes how suitable a song is for dancing on a scale from 0 to 100, with 0 being the least danceable and 100 being the most danceable.
Danceability Distribution of Different Genres
ggplot(spotify_songs, mapping = aes(x = danceability, fill = playlist_genre)) +
geom_density(alpha = 0.5) +
theme_minimal() +
theme(plot.title=element_text(hjust=0.5)) +
labs(x = "Danceability", y = "Density", fill = "Genre", title = "Danceability Distribution of Different Genres")

Here, we can see the distibution of danceability ratings for each genre. There are 6 density plots that correspond to each genre and that overlap one another. The danceability is mapped to the x axis and the playlist_genre is mapped to fill the density plots in a color different for each genre. The rock genre, has the lowest peak at around 0.5 danceability. Other genres, like rap, latin, r&b, and pop have peaks at around 0.75.
To get a better understanding of just how related danceability is to song popularity, we can compare the two.
How Danceability Affects Song Popularity
ggplot(spotify_songs, mapping = aes(x = danceability, y = track_popularity, color = playlist_genre)) +
geom_smooth(se = FALSE) +
theme_minimal() +
theme(plot.title=element_text(hjust=0.5)) +
labs(x = "Danceability", y = "Song Popularity", color = "Genre", title = "How Danceability Affects Song Popularity ")

Here, we can see the relationship between danceability and song popularity for each genre. The danceability is mapped to the x axis, the track_popularity is mapped to the y-axis, and playlist_genre is mapped to color. This was essentially a scatterplot, but since there were so many points, it was hard to understand what was going on and the trends that were present. Therefore what is shown, is the line of best fit for each genre without including the individual points. For most genres (pop, latin, rock, and rap), there is a clear positive correlation between the two variables. The higher the danceability, the more popular a song is. The EDM genre continues to be the outlier of all the genres, with it’s popularity overall decreasing the more danceable the song is.
Of course, there a ton of other factors that could play into a song’s popularity, but it is clear that the danceability of a song is huge indicator in whether or not a song is popular or not (in most genres).
LS0tCnRpdGxlOiAiRG8gWW91IExpa2UgdG8gRGFuY2U/IgphdXRob3I6ICJDYXJvbGluZSBNYXphcmllZ29zIgpkYXRlOiAiMDIvMTgvMjAyMiIKb3V0cHV0OiAKICBodG1sX2RvY3VtZW50OgogICAgdGhlbWU6IGZsYXRseQogICAgdG9jOiB0cnVlCiAgICB0b2NfZmxvYXQ6IHRydWUKICAgIGNvZGVfZG93bmxvYWQ6IHRydWUKLS0tCgpgYGB7ciwgd2FybmluZyA9IEZBTFNFLCBtZXNzYWdlID0gRkFMU0V9CiMgTG9hZCBhbnkgUiBQYWNrYWdlcyB5b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