This project aims to analyze the Tidy Tuesday Spotify Songs dataset (https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-21/spotify_songs.csv) and answer questions such:
1-How many genres are present in this data set:
2-What is the most popular genre based on our data?
3-What are the most popular songs released in between the years 2015-2020.
4-What are the most popular songs?
5-What is the subgenre with the longest duration on average.
6-What is the number of songs by artists released between 2015 and 2020?
7-What is the genre with the highest positive?
8-What are the genres with the highest Energy?
9-What is the most popular artist based on Popularity?
10-Correlation between variables and Popularity.
To do this, I will focus on a few of the 23 columns in the data set and explore them in detail.
I will present the data, select the variables of interest, visualize and summarize my findings.
install.packages("tidyverse",repos="http://cran.us.r-project.org")
install.packages("wordcloud",repos="http://cran.us.r-project.org")
install.packages("RColorBrewer",repos="http://cran.us.r-project.org")
install.packages("wordcloud2",repos="http://cran.us.r-project.org")
library(readr) #Provide fast and friendly way.
library(dplyr) #For the data manipulation.
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse) ###essential for interact with the data.
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2) # helps visualize data, producing aesthetic plots
library(lubridate) #helps wrangle data attributes
library(stringr) # to work with character strings in R.
library(wordcloud)
## Loading required package: RColorBrewer
library(wordcloud)
library(RColorBrewer)
library(wordcloud2)
###Confirming if it has been renamed correctly
head(spotify_data)
## # A tibble: 6 × 19
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 I Don'… Ed Sh… 66 I Do… 2019-06-14 pop dance p… 0.748 0.916 6
## 2 Memori… Maroo… 67 Memo… 2019-12-13 pop dance p… 0.726 0.815 11
## 3 All th… Zara … 70 All … 2019-07-05 pop dance p… 0.675 0.931 1
## 4 Call Y… The C… 60 Call… 2019-07-19 pop dance p… 0.718 0.93 7
## 5 Someon… Lewis… 69 Some… 2019-03-05 pop dance p… 0.65 0.833 1
## 6 Beauti… Ed Sh… 67 Beau… 2019-07-11 pop dance p… 0.675 0.919 8
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
We can observe some changes made to the raw data, like the columns names change for better visualization.
### Listing distinct values in columns
Clean_data<-spotify_data %>%
filter(!duplicated(Track))
### Finding any missing values
Clean_data %>%
select_all() %>%
filter(BPMs=="" |
Energy==""|
Dance==""|
Loudness==""|
Speechiness==""|
Duration==""|
Instrumentalness=="")
Clean_data<-na.omit(Clean_data)
view(Clean_data)
unique.data.frame(Clean_data)
The table below shows the final results of the cleaning and tidying process of the data. We get, 19 columns (variables) with the first 6 rows.
head(Clean_data)
## # A tibble: 6 × 19
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 I Don'… Ed Sh… 66 I Do… 2019-06-14 pop dance p… 0.748 0.916 6
## 2 Memori… Maroo… 67 Memo… 2019-12-13 pop dance p… 0.726 0.815 11
## 3 All th… Zara … 70 All … 2019-07-05 pop dance p… 0.675 0.931 1
## 4 Call Y… The C… 60 Call… 2019-07-19 pop dance p… 0.718 0.93 7
## 5 Someon… Lewis… 69 Some… 2019-03-05 pop dance p… 0.65 0.833 1
## 6 Beauti… Ed Sh… 67 Beau… 2019-07-11 pop dance p… 0.675 0.919 8
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
The data set contains 19 different variables for each songs such Track title, Artist name, Genre, sub genre, Popularity, Energy, loudness, etc. Here are all the variable and their descriptions:
1-Track: Song’s Title
2-Artist: Song’s Artist
3-Popularity: The higher the value the more popular the song is.
4-Album: The album name.
5-Release_date: Date when the album was released.
6-Genre: Playlist genre.
7-Sub genre: Playlist subgenre.
8-Dance: Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable.
9-Energy: Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of intensity and activity. Typically, energetic tracks feel fast, loud, and noisy. For example, death metal has high energy, while a Bach prelude scores low on the scale. Perceptual features contributing to this attribute include dynamic range, perceived loudness, timbre, onset rate, and general entropy.
10-Key: The estimated overall key of the track. Integers map to pitches using standard Pitch Class notation. (Ex. 0=C, 1=C#/Db, 2=D).
11-Loudness: The overall loudness of a track in decibels (dB). Loudness values are averaged across the entire track and are useful for comparing relative loudness of tracks. Loudness is the quality of a sound that is the primary psychological correlate of physical strength (amplitude). Values typical range between -60 and 0 db.
12-Scale_mode: Mode indicates the modality (major or minor) of a track, the type of scale from which its melodic content is derived. Major is represented by 1 and minor is 0.
13-Speechiness: Speechiness detects the presence of spoken words in a track. The more exclusively speech-like the recording (e.g. talk show, audio book, poetry), the closer to 1.0 the attribute value. Values above 0.66 describe tracks that are probably made entirely of spoken words. Values between 0.33 and 0.66 describe tracks that may contain both music and speech, either in sections or layered, including such cases as rap music. Values below 0.33 most likely represent music and other non-speech-like tracks.
14-Acousticness: A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic.
15-Instrumentalness: Predicts whether a track contains no vocals. “Ooh” and “aah” sounds are treated as instrumental in this context. Rap or spoken word tracks are clearly “vocal”. The closer the instrumentalness value is to 1.0, the greater likelihood the track contains no vocal content. Values above 0.5 are intended to represent instrumental tracks, but confidence is higher as the value approaches 1.0.
16-Liveness: Detects the presence of an audience in the recording. Higher liveness values represent an increased probability that the track was performed live. A value above 0.8 provides strong likelihood that the track is live.
17-Valence: 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).
18-BPMs: Tempo: The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration.
19-Duration: Duration of song in milliseconds
Here, we have a summary of the data to visualize descriptive statistics
## Track Artist Popularity Album
## Length:23449 Length:23449 Min. : 0.00 Length:23449
## Class :character Class :character 1st Qu.:23.00 Class :character
## Mode :character Mode :character Median :43.00 Mode :character
## Mean :39.74
## 3rd Qu.:58.00
## Max. :98.00
## Release_date Genre Subgenre Dance
## Length:23449 Length:23449 Length:23449 Min. :0.0000
## Class :character Class :character Class :character 1st Qu.:0.5630
## Mode :character Mode :character Mode :character Median :0.6720
## Mean :0.6552
## 3rd Qu.:0.7620
## Max. :0.9830
## Energy Key Loudness Scale_mode
## Min. :0.000175 Min. : 0.000 Min. :-46.448 Min. :0.0000
## 1st Qu.:0.578000 1st Qu.: 2.000 1st Qu.: -8.341 1st Qu.:0.0000
## Median :0.720000 Median : 6.000 Median : -6.285 Median :1.0000
## Mean :0.696638 Mean : 5.374 Mean : -6.848 Mean :0.5667
## 3rd Qu.:0.841000 3rd Qu.: 9.000 3rd Qu.: -4.727 3rd Qu.:1.0000
## Max. :1.000000 Max. :11.000 Max. : 1.275 Max. :1.0000
## Speechiness Acousticness Instrumentalness Liveness
## Min. :0.0000 Min. :0.0000 Min. :0.0000000 Min. :0.0000
## 1st Qu.:0.0412 1st Qu.:0.0148 1st Qu.:0.0000000 1st Qu.:0.0927
## Median :0.0637 Median :0.0827 Median :0.0000192 Median :0.1270
## Mean :0.1103 Mean :0.1811 Mean :0.0940749 Mean :0.1916
## 3rd Qu.:0.1390 3rd Qu.:0.2660 3rd Qu.:0.0069600 3rd Qu.:0.2500
## Max. :0.9180 Max. :0.9940 Max. :0.9940000 Max. :0.9960
## Valence BPMs Duration
## Min. :0.0000 Min. : 0.00 Min. : 4000
## 1st Qu.:0.3300 1st Qu.: 99.97 1st Qu.:187200
## Median :0.5130 Median :122.00 Median :216133
## Mean :0.5114 Mean :121.08 Mean :226107
## 3rd Qu.:0.6950 3rd Qu.:134.78 3rd Qu.:254493
## Max. :0.9910 Max. :239.44 Max. :517810
## # A tibble: 6 × 6
## # Groups: Release_date [6]
## Track Artist Genre Release_date Duration Popularity
## <chr> <chr> <chr> <chr> <dbl> <dbl>
## 1 The Box Roddy Ricch rap 2019-12-06 196653 98
## 2 Blinding Lights The Weeknd pop 2019-11-29 201573 98
## 3 Tusa KAROL G pop 2019-11-07 200960 98
## 4 Memories Maroon 5 pop 2019-09-20 189486 98
## 5 everything i wanted Billie Eilish pop 2019-11-13 245426 97
## 6 Don't Start Now Dua Lipa pop 2019-10-31 183290 97
After analyzing the data, it can be observed that the song “The Box” by Roddy Rich is the most popular song in the rap genre with a score of 98. The most popular genre overall is pop.
## # A tibble: 6 × 2
## Subgenre mean_duration
## <chr> <dbl>
## 1 new jack swing 276305.
## 2 progressive electro house 267515.
## 3 album rock 254884.
## 4 classic rock 253736.
## 5 southern hip hop 247695.
## 6 permanent wave 245131.
Above, we can see the first 6 songs with the longest duration in milliseconds. For most of this data, the subgenre with the longest duration in milliseconds is new jack swing.
## # A tibble: 6 × 2
## Artist no.of.songs
## <chr> <int>
## 1 Martin Garrix 53
## 2 The Chainsmokers 51
## 3 Logic 50
## 4 Kygo 37
## 5 Dimitri Vegas & Like Mike 36
## 6 Drake 34
We find that Martin Garrix released 53 songs between 2015-2022.
## # A tibble: 6 × 19
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 Low Ri… War 36 The … 2003-01-01 rock classic… 0.815 0.676 0
## 2 What a… The D… 68 Minu… 1978 rock classic… 0.758 0.378 8
## 3 Counte… 1986 … 25 Crys… 1987-02-04 r&b neo soul 0.717 0.725 4
## 4 Can't … Souls… 52 Can'… 1998 edm progres… 0.747 0.973 4
## 5 Materi… Madon… 54 Like… 1984-11-12 pop electro… 0.78 0.63 0
## 6 You Lo… ripma… 49 You … 2020-01-08 pop indie p… 0.88 0.74 5
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
According to the valence, which is a measure of a song’s positivity, we can say that songs like “Low Rider” by the artist “War” or “What a Fool Believes” by “The Doobie Brothers” are more happy or chillful. To confirm this, I played “Low Rider” on YouTube and found that it is indeed a happy song, based on its rhythm and swing.
## # A tibble: 6 × 19
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 Rain … Natur… 52 Natu… 2011-02-16 latin tropical 0.16 1 5
## 2 Chill… Pinet… 57 Waves 2019-10-03 latin tropical 0.141 1 10
## 3 Fores… Rain … 75 Peac… 2019-09-06 latin tropical 0.0771 1 3
## 4 Capta… Capta… 48 Capt… 2008-11-21 pop dance p… 0.667 0.999 1
## 5 Staat… Agono… 0 For … 2008-10-31 pop electro… 0.507 0.999 4
## 6 Immor… Solit… 0 Immo… 2009-05-29 pop electro… 0.693 0.999 10
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
## # A tibble: 6 × 19
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 If Onl… Fusio… 41 If O… 2016-04-01 edm progres… 0.983 0.936 9
## 2 Mega R… DJ Zs… 27 Mega… 2018-08-24 edm electro… 0.981 0.794 0
## 3 Ice Ic… Vanil… 70 Vani… 2008-11-04 pop dance p… 0.979 0.792 2
## 4 Enseña… DJ Go… 65 Ense… 2019-07-19 latin reggaet… 0.979 0.923 3
## 5 Cha Ch… DJ Ca… 54 Cha … 2004-01-01 latin latin h… 0.978 0.691 6
## 6 Funky … Dave 72 Funk… 2018-10-04 rap hip hop 0.975 0.535 1
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
## # A tibble: 1 × 19
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 47 - R… Anuel… 64 47 (… 2017-03-31 latin latin h… 0.711 0.699 6
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
## # A tibble: 1 × 19
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 Hi, Ho… DREAM… 0 Drea… 1989-03-21 rock album r… 0 0.315 1
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
Based on our analysis, the Latin music genre “Rain Forest and Tropical Beach Sound” and “Chill Waves & Wind in Leaves” are the most energetic songs. We believe that these songs are rated highly for their dynamic nature and overall entropy. Songs in the electronic dance music (EDM) genre or most remixes are typically considered more danceable. This is because DJs often tweak songs to make them more energetic, which naturally enhances their danceability. Additionally, these songs tend to be longer than usual, making them perfect for parties. It’s no surprise that EDM is a popular genre for dancing!
## # A tibble: 6 × 19
## # Groups: Artist, Popularity [6]
## Track Artist Popularity Album Release_date Genre Subgenre Dance Energy Key
## <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 Tusa KAROL… 98 Tusa 2019-11-07 pop dance p… 0.803 0.715 2
## 2 Memori… Maroo… 98 Memo… 2019-09-20 pop dance p… 0.764 0.32 11
## 3 Blindi… The W… 98 Blin… 2019-11-29 pop dance p… 0.513 0.796 1
## 4 The Box Roddy… 98 Plea… 2019-12-06 rap hip hop 0.896 0.586 10
## 5 everyt… Billi… 97 ever… 2019-11-13 pop dance p… 0.704 0.225 6
## 6 Don't … Dua L… 97 Don'… 2019-10-31 pop post-te… 0.794 0.793 11
## # ℹ 9 more variables: Loudness <dbl>, Scale_mode <dbl>, Speechiness <dbl>,
## # Acousticness <dbl>, Instrumentalness <dbl>, Liveness <dbl>, Valence <dbl>,
## # BPMs <dbl>, Duration <dbl>
On the other hand, the most popular artist based on the popularity rating is the Latin artist Karol G, followed by Maroon 5, The Weeknd, and Billie Eilish. Almost all of these artists belong to the pop genre and have relatively similar popularity rates.
## $title
## [1] "Most Popular Genre"
##
## attr(,"class")
## [1] "labels"
We can see the most popular genres based on popularity ratings. Pop is still the most popular, followed by rap.
We plotted the number of songs released by various artists between 2015 and 2020. Martin Garrix has released around 50 songs followed by The Chainsmokers and Logic.
Finally, we compare Popularity with some variables like, BPMs, Energy, Danceability, etc. To verify if exist correlation between them.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] 0.00497862
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] -0.1041632
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] 0.1501787
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] -0.17335
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] -0.07349685
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] 0.04196206
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] 0.03222995
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] 0.01098873
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## [1] 0.1608376
After plotting the correlations, we have found that some of the variables are not correlated with Popularity. We can say that a correlation exists between variables when the resulting values are either greater than zero (positive correlation) or less than zero (negative correlation). In this case, we have obtained results close to zero, indicating a lack of correlation between the variables.
For this project, we applied what we learned in our statistical software R class using a real Spotify songs dataset. We aimed to answer some questions such as the number of genres present, the most popular songs, and the most popular artists. We also wanted to evaluate if there was any correlation between variables such as Popularity, Energy, Danceability, etc.
The analysis provided some interesting insights:
We found that the most popular genres among the six genres were Pop and Rap.
Karol G, Maroon 5, The Weeknd, Roddy Rich, Billie Eilish, and Dua Lipa were the six most popular artists.
Listening to positive songs can help motivate yourself. So, I recommend songs like “Low Rider” by War or “What a Fool Believes” by The Doobie Brothers.
It appears that the rock genre has a lot of positive songs in this category.
Based on the correlation result, this data do not show any correlation between Popularity, with the energy, BPMs, or Valence.
Visualizing the Correlation between Positivity and Enegry we observe that the r&b genre appears to show a positive releationship.