I will be trying to analyze the data in a way that helps recognize how some specific aspects of music may or may not contribute to popularity. This will be shown through the various genres and how popularity fluctuates over time. As someone that never really developed my own sense of taste until later in life, I am quite curious as to which music garnered the most popularity within this very large datapool.
I will use the following packages for my project:
library(tidyverse) #Tidying up data, data collection
library(ggplot2) #Data visualization with graphs
library(treemap) #Further vizualization through treemap
These two packages were heavily used in class for standard data collection, cleanup, etc. In addition to them, I used treemap as a way to visualize some of my data in a new way, as per recommendation.
The original data set had 23 variables. There were 15 missing values in the data set, with 5 each being from the following variables: track_name, track_artist and track_album_name. Because these variables were either too plentiful or specific to one particular song, I felt that they weren’t going to be particularly helpful in my planned analysis of music popularity. For that reason, I found it necessary to isolate and remove these missing values, as I am abstaining from using the variables.
Further, while I initially planned to examine the rest of the variables within the data set, I ultimately decided that a more isolated look at the variables of genre, subgenre and track_album_release date would be more effective and streamlined. After shaving down to these remaining variables, I created a few new ones, titled track_popularity, decade and decade_popularity to help as measures of popularity and for further analysis/visualization. With the variables of genre and subgenre, I also changed them into factors, for the purpose of making them easier to manipulate.
General Cleaning:
spotify_df$playlist_genre <- as.factor(spotify_df$playlist_genre)
spotify_df$playlist_subgenre <- as.factor(spotify_df$playlist_subgenre)
#5 missing values
sum(is.na(spotify_df$track_name))
#5 missing values
sum(is.na(spotify_df$track_artist))
#5 missing values
sum(is.na(spotify_df$track_album_name))
spotify_df <- spotify_df %>%
select(track_album_release_date, playlist_genre, playlist_subgenre, track_popularity)
Creation of decade, track popularity, and decade popularity variables:
spotify_df <- spotify_df %>%
mutate(track_album_release_date = parse_date_time(track_album_release_date, c("mdy", "y", "ym", "ymd"))) %>%
mutate(decade = case_when(year(track_album_release_date) >= "1950" & year(track_album_release_date) < "1960" ~ "Fifties",
year(track_album_release_date) >= "1960" & year(track_album_release_date) < "1970" ~ "Sixties",
year(track_album_release_date) >= "1970" & year(track_album_release_date) < "1980" ~ "Seventies",
year(track_album_release_date) >= "1980" & year(track_album_release_date) < "1990" ~ "Eighties",
year(track_album_release_date) >= "1990" & year(track_album_release_date) < "2000" ~ "Nineties",
year(track_album_release_date) >= "2000" & year(track_album_release_date) < "2010" ~ "Two-Thousands",
year(track_album_release_date) >= "2010" & year(track_album_release_date) < "2020" ~ "Twenty-Tens",
year(track_album_release_date) >= "2020" & year(track_album_release_date) < "2030" ~ "Twenty-Twenties",
TRUE ~ "BAD")) %>%
mutate(decade = as.factor(decade)) %>%
mutate(decade = fct_relevel(decade, "Fifties", "Sixties", "Seventies", "Eighties", "Nineties", "Two-Thousands", "Twenty-Tens", "Twenty-Twenties")) %>%
group_by(decade) %>%
mutate(decade_popularity = mean(track_popularity)) %>%
ungroup()
Cleaned data set’s top 10 observations:
head(spotify_df, n = 10)
ggplot(data = spotify_df, aes(x = decade)) +
geom_line(aes(y = decade_popularity, group = 1, color = "red"), show.legend = FALSE) +
scale_x_discrete("Decades")+
scale_y_continuous("Average Popularity")+
ggtitle("Figure 1: Average Popularity by Decade")
Next I took a look at genres and their popularity by decades. Per recommendation, my main way of visualizing this data was through a treemap. Treemaps demonstrate hierarchal data based on rectangles of various sizes occupying the space of larger subjects. In the case of this treemap, decades would make up the larger boxes and the genres would make up the space. Larger boxes meant they were more popular genres. In terms of observations, immediately interesting to me was how much space the twenty-tens took up on the treemap, which I assume is attributed to just a sheer number of data mainly being from the 2010s in the spotify dataframe. Within each year, I think some more notably genres would be edm in the 2010’s, rock in the 2000’s and 80’s and R&B for the 90’s.
treemap(spotify_df, index = c("decade", "playlist_genre"), vSize = "decade_popularity", title = "Figure 2: Genre Popularity by Decade")
Lastly, I examined different genre’s subgenres just to see what they comprised of and what were most popular. Quite a few things were interesting to me here, first of all being that latin had such a presence among the genres/subgenres. In fact, most of the top placements for subgenre popularity caught me off guard. Indie popitism for pop, urban contemporary for R&B, and permanent wave for rock especially stood out as subgenres I was unaware of or were suprised at in them taking the top spot.
treemap(spotify_df, index = c("playlist_genre", "playlist_subgenre"), vSize = "track_popularity", title = "Figure 3: Subgenres Popularity")
This wraps up an admittedly brief but hopefully interesting analysis at some aspects of music popularity within this Spotify data frame. It appears that many people view music as timeless, and while people’s preferences have inevitably changed over time, the release date in of itself is not something that heavily contributes to music popularity or lack thereof. Further, the majority of music present on Spotify, given this data frame is any indication, is more recent. I also personally learned a lot about new genres/subgenres of music in this with a lot of subgenres surprising me with their popularity, placements, etc.