Data Explanation

Our data obtained directly from Spotify Web API. For API connection, we created “Client ID” and “Client Secret” from Spotify for Developers Website. For this purpose, “spotifyr” package used for making connection.

Accessing Spotifty Web API

When connection is made successfully, we can access lots of difrent type data such as aritst, albums, tracks, user profile etc. Here is the Spotify API References. In our project, we will usually use playlist, artist and track data.

Initial Analysis

Turkey Top 50 Analysis

turkey_top_50_id="37i9dQZEVXbIVYVBNw9D5K"
turkey_top50_audio_features <- get_playlist_audio_features("spotifycharts",turkey_top_50_id)
glimpse(turkey_top50_audio_features)
## Observations: 50
## Variables: 61
## $ playlist_id                        <chr> "37i9dQZEVXbIVYVBNw9D5K", "...
## $ playlist_name                      <chr> "Turkey Top 50", "Turkey To...
## $ playlist_img                       <chr> "https://charts-images.scdn...
## $ playlist_owner_name                <chr> "spotifycharts", "spotifych...
## $ playlist_owner_id                  <chr> "spotifycharts", "spotifych...
## $ danceability                       <dbl> 0.801, 0.743, 0.810, 0.690,...
## $ energy                             <dbl> 0.688, 0.680, 0.631, 0.562,...
## $ key                                <int> 9, 5, 4, 6, 9, 7, 11, 5, 10...
## $ loudness                           <dbl> -6.620, -4.344, -7.855, -8....
## $ mode                               <int> 1, 0, 0, 1, 0, 0, 0, 0, 0, ...
## $ speechiness                        <dbl> 0.1130, 0.1030, 0.3270, 0.0...
## $ acousticness                       <dbl> 0.27800, 0.11300, 0.11700, ...
## $ instrumentalness                   <dbl> 8.88e-03, 1.23e-01, 0.00e+0...
## $ liveness                           <dbl> 0.1500, 0.1830, 0.1190, 0.1...
## $ valence                            <dbl> 0.4100, 0.6940, 0.4070, 0.6...
## $ tempo                              <dbl> 158.003, 180.059, 144.978, ...
## $ track.id                           <chr> "2KlbLTnQ5Wch2oOelW0Y2k", "...
## $ analysis_url                       <chr> "https://api.spotify.com/v1...
## $ time_signature                     <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, ...
## $ added_at                           <chr> "1970-01-01T00:00:00Z", "19...
## $ is_local                           <lgl> FALSE, FALSE, FALSE, FALSE,...
## $ primary_color                      <lgl> NA, NA, NA, NA, NA, NA, NA,...
## $ added_by.href                      <chr> "https://api.spotify.com/v1...
## $ added_by.id                        <chr> "", "", "", "", "", "", "",...
## $ added_by.type                      <chr> "user", "user", "user", "us...
## $ added_by.uri                       <chr> "spotify:user:", "spotify:u...
## $ added_by.external_urls.spotify     <chr> "https://open.spotify.com/u...
## $ track.artists                      <list> [<data.frame[2 x 6]>, <dat...
## $ track.available_markets            <list> [<"AD", "AE", "AR", "AT", ...
## $ track.disc_number                  <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
## $ track.duration_ms                  <int> 154251, 196583, 185566, 196...
## $ track.episode                      <lgl> FALSE, FALSE, FALSE, FALSE,...
## $ track.explicit                     <lgl> TRUE, FALSE, TRUE, TRUE, TR...
## $ track.href                         <chr> "https://api.spotify.com/v1...
## $ track.is_local                     <lgl> FALSE, FALSE, FALSE, FALSE,...
## $ track.name                         <chr> "Wir sind Kral", "AYA", "Ar...
## $ track.popularity                   <int> 44, 71, 76, 75, 50, 78, 46,...
## $ track.preview_url                  <chr> NA, NA, "https://p.scdn.co/...
## $ track.track                        <lgl> TRUE, TRUE, TRUE, TRUE, TRU...
## $ track.track_number                 <int> 11, 1, 1, 1, 6, 1, 10, 1, 1...
## $ track.type                         <chr> "track", "track", "track", ...
## $ track.uri                          <chr> "spotify:track:2KlbLTnQ5Wch...
## $ track.album.album_type             <chr> "album", "single", "single"...
## $ track.album.artists                <list> [<data.frame[2 x 6]>, <dat...
## $ track.album.available_markets      <list> [<"AD", "AE", "AR", "AT", ...
## $ track.album.href                   <chr> "https://api.spotify.com/v1...
## $ track.album.id                     <chr> "3gSlFOtOhV1OS3qTQx4g55", "...
## $ track.album.images                 <list> [<data.frame[3 x 3]>, <dat...
## $ track.album.name                   <chr> "Lights Out", "AYA", "Arkad...
## $ track.album.release_date           <chr> "2019-11-14", "2019-09-20",...
## $ track.album.release_date_precision <chr> "day", "day", "day", "day",...
## $ track.album.total_tracks           <int> 12, 1, 1, 1, 12, 1, 12, 1, ...
## $ track.album.type                   <chr> "album", "album", "album", ...
## $ track.album.uri                    <chr> "spotify:album:3gSlFOtOhV1O...
## $ track.album.external_urls.spotify  <chr> "https://open.spotify.com/a...
## $ track.external_ids.isrc            <chr> "DECE71900765", "NLG6619008...
## $ track.external_urls.spotify        <chr> "https://open.spotify.com/t...
## $ video_thumbnail.url                <lgl> NA, NA, NA, NA, NA, NA, NA,...
## $ key_name                           <chr> "A", "F", "E", "F#", "A", "...
## $ mode_name                          <chr> "major", "minor", "minor", ...
## $ key_mode                           <chr> "A major", "F minor", "E mi...

Adding Sentiments in Each Track

The purpose of this function named “classify_track_sentiment” is important for us to work primarily to reveal the mood of songs and song lists along these lines. Energy and valence are two important factors in terms of interpreting emotion in music. The variations of these two factors, which have values between 0 and 1, in this range determine the songs to be turbulent/angry, happy/joyful, sad/depressing and chill/peaceful.

According to Get Audio Features for a Track, explanations of the corresponding factors are as follows.

Energy

Data type: Float
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.

Valence

Data type: Float
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).

classify_track_sentiment <- function(valence, energy) {
    if (is.na(valence) | is.na(energy)) {
        return(NA)
    }
    else if (valence >= .5) {
        if (energy >= .5) {
            return('Happy/Joyful')
        } else {
            return('Chill/Peaceful')
        }
    } else {
        if (energy >= .5) {
            return('Turbulent/Angry')
        } else {
            return('Sad/Depressing')
        }
    }
}
track_sentiment = c()
for (i in 1:50){
  track_sentiment[i]= classify_track_sentiment(turkey_top50_audio_features[[15]][[i]],turkey_top50_audio_features[[7]][[i]])
  
}
turkey_top50_audio_features<-cbind(turkey_top50_audio_features,track_sentiment)

Selection of Necessary Columns for Analysing

track_id="6bBnnrknLbDoOCUdKMkmnq"
track_audio_analyse_selection<- turkey_top50_audio_features %>% select(track.name,track.id,track.artists,track.album.images,track.album.release_date,track.popularity,danceability:tempo,track_sentiment,track.duration_ms)
head(track_audio_analyse_selection,width=10)
##      track.name               track.id
## 1 Wir sind Kral 2KlbLTnQ5Wch2oOelW0Y2k
## 2           AYA 4IJEw3fDvS6XF4sDc3bvjK
## 3       Arkadaş 6bBnnrknLbDoOCUdKMkmnq
## 4       Neresi? 5m42G9KcZupRGXyBj2dPzV
## 5   Yemin Olsun 1BzTI6CkluzAJsXFRkXTaR
## 6         Nalan 1LNUxWJifZNEPpd273N2le
##                                                                                                                                                                                                                                                                                                                                                                                         track.artists
## 1   https://api.spotify.com/v1/artists/5pVRwX5ZQR7hfJ18w8ZYkl, https://api.spotify.com/v1/artists/6LnJKrtFnTEGdbWQ2riWCL, 5pVRwX5ZQR7hfJ18w8ZYkl, 6LnJKrtFnTEGdbWQ2riWCL, Ufo361, Ezhel, artist, artist, spotify:artist:5pVRwX5ZQR7hfJ18w8ZYkl, spotify:artist:6LnJKrtFnTEGdbWQ2riWCL, https://open.spotify.com/artist/5pVRwX5ZQR7hfJ18w8ZYkl, https://open.spotify.com/artist/6LnJKrtFnTEGdbWQ2riWCL
## 2    https://api.spotify.com/v1/artists/2y1VzMKAa5nmfXKtJL9jnj, https://api.spotify.com/v1/artists/6LnJKrtFnTEGdbWQ2riWCL, 2y1VzMKAa5nmfXKtJL9jnj, 6LnJKrtFnTEGdbWQ2riWCL, Murda, Ezhel, artist, artist, spotify:artist:2y1VzMKAa5nmfXKtJL9jnj, spotify:artist:6LnJKrtFnTEGdbWQ2riWCL, https://open.spotify.com/artist/2y1VzMKAa5nmfXKtJL9jnj, https://open.spotify.com/artist/6LnJKrtFnTEGdbWQ2riWCL
## 3                                                                                                                                                                                                  https://api.spotify.com/v1/artists/2kS0jWMkkFBL0mrl0VotD0, 2kS0jWMkkFBL0mrl0VotD0, Ben Fero, artist, spotify:artist:2kS0jWMkkFBL0mrl0VotD0, https://open.spotify.com/artist/2kS0jWMkkFBL0mrl0VotD0
## 4 https://api.spotify.com/v1/artists/6q1sTU51oryTTcWTPTd0VC, https://api.spotify.com/v1/artists/6E2u900yhuZ7ihtXUXvmi9, 6q1sTU51oryTTcWTPTd0VC, 6E2u900yhuZ7ihtXUXvmi9, BEGE, EFESAVAGE, artist, artist, spotify:artist:6q1sTU51oryTTcWTPTd0VC, spotify:artist:6E2u900yhuZ7ihtXUXvmi9, https://open.spotify.com/artist/6q1sTU51oryTTcWTPTd0VC, https://open.spotify.com/artist/6E2u900yhuZ7ihtXUXvmi9
## 5   https://api.spotify.com/v1/artists/5pVRwX5ZQR7hfJ18w8ZYkl, https://api.spotify.com/v1/artists/6LnJKrtFnTEGdbWQ2riWCL, 5pVRwX5ZQR7hfJ18w8ZYkl, 6LnJKrtFnTEGdbWQ2riWCL, Ufo361, Ezhel, artist, artist, spotify:artist:5pVRwX5ZQR7hfJ18w8ZYkl, spotify:artist:6LnJKrtFnTEGdbWQ2riWCL, https://open.spotify.com/artist/5pVRwX5ZQR7hfJ18w8ZYkl, https://open.spotify.com/artist/6LnJKrtFnTEGdbWQ2riWCL
## 6                                                                                                                                                                                            https://api.spotify.com/v1/artists/4XP7cGw4t8BqZ8Du5q3bHg, 4XP7cGw4t8BqZ8Du5q3bHg, Emir Can İğrek, artist, spotify:artist:4XP7cGw4t8BqZ8Du5q3bHg, https://open.spotify.com/artist/4XP7cGw4t8BqZ8Du5q3bHg
##                                                                                                                                                                                                                 track.album.images
## 1 640, 300, 64, https://i.scdn.co/image/63116c63e8b3434a3a21a929bda0e34b73988f53, https://i.scdn.co/image/3fd9026c9839ea52850b4543356d5c39ff2c237d, https://i.scdn.co/image/0b21550a74f848aca324b220ed19882598f32cd1, 640, 300, 64
## 2 640, 300, 64, https://i.scdn.co/image/9911b983e1ce76bfa5aab21b425491b579412cbc, https://i.scdn.co/image/2e3278d06aab8a47640c0c96d1b65b46cc6587dc, https://i.scdn.co/image/86f9e2933aa332826d4dd974be39e09977f7ef85, 640, 300, 64
## 3 640, 300, 64, https://i.scdn.co/image/dce46548775e6eff6c0f05263c6abf3374f7aea3, https://i.scdn.co/image/fb111a8f4cac255e120119caec4903a370f8428d, https://i.scdn.co/image/a1fb2f0de85c596b39327967a095653c06de0ff1, 640, 300, 64
## 4 640, 300, 64, https://i.scdn.co/image/5a6f879a99e54901201059ea135df6a775d46fb9, https://i.scdn.co/image/1b6f8342e571a945585253bf2ba91042bbfb2f28, https://i.scdn.co/image/b1ed1abc736a87258a126ea17addce7978678865, 640, 300, 64
## 5 640, 300, 64, https://i.scdn.co/image/63116c63e8b3434a3a21a929bda0e34b73988f53, https://i.scdn.co/image/3fd9026c9839ea52850b4543356d5c39ff2c237d, https://i.scdn.co/image/0b21550a74f848aca324b220ed19882598f32cd1, 640, 300, 64
## 6 640, 300, 64, https://i.scdn.co/image/1a9bab660f38203f070823c9a856e13725554d84, https://i.scdn.co/image/f936e6c7261d98bb2b995bc0775553f6aadb876c, https://i.scdn.co/image/a01489129407faef7fc3324bc59f570f6528d36b, 640, 300, 64
##   track.album.release_date track.popularity danceability energy key
## 1               2019-11-14               44        0.801  0.688   9
## 2               2019-09-20               71        0.743  0.680   5
## 3               2019-11-08               76        0.810  0.631   4
## 4               2019-11-08               75        0.690  0.562   6
## 5               2019-11-14               50        0.810  0.582   9
## 6               2019-09-06               78        0.540  0.418   7
##   loudness mode speechiness acousticness instrumentalness liveness valence
## 1   -6.620    1      0.1130        0.278          0.00888    0.150   0.410
## 2   -4.344    0      0.1030        0.113          0.12300    0.183   0.694
## 3   -7.855    0      0.3270        0.117          0.00000    0.119   0.407
## 4   -8.272    1      0.0728        0.499          0.53100    0.141   0.652
## 5   -6.527    0      0.0654        0.111          0.00030    0.116   0.310
## 6  -15.570    0      0.0761        0.190          0.68500    0.198   0.189
##     tempo track_sentiment track.duration_ms
## 1 158.003 Turbulent/Angry            154251
## 2 180.059    Happy/Joyful            196583
## 3 144.978 Turbulent/Angry            185566
## 4 159.986    Happy/Joyful            196000
## 5 109.983 Turbulent/Angry            194381
## 6  91.042  Sad/Depressing            199958
  glimpse(track_audio_analyse_selection)
## Observations: 50
## Variables: 19
## $ track.name               <chr> "Wir sind Kral", "AYA", "Arkadaş", "N...
## $ track.id                 <chr> "2KlbLTnQ5Wch2oOelW0Y2k", "4IJEw3fDvS...
## $ track.artists            <list> [<data.frame[2 x 6]>, <data.frame[2 ...
## $ track.album.images       <list> [<data.frame[3 x 3]>, <data.frame[3 ...
## $ track.album.release_date <chr> "2019-11-14", "2019-09-20", "2019-11-...
## $ track.popularity         <int> 44, 71, 76, 75, 50, 78, 46, 64, 53, 7...
## $ danceability             <dbl> 0.801, 0.743, 0.810, 0.690, 0.810, 0....
## $ energy                   <dbl> 0.688, 0.680, 0.631, 0.562, 0.582, 0....
## $ key                      <int> 9, 5, 4, 6, 9, 7, 11, 5, 10, 8, 6, 8,...
## $ loudness                 <dbl> -6.620, -4.344, -7.855, -8.272, -6.52...
## $ mode                     <int> 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0...
## $ speechiness              <dbl> 0.1130, 0.1030, 0.3270, 0.0728, 0.065...
## $ acousticness             <dbl> 0.27800, 0.11300, 0.11700, 0.49900, 0...
## $ instrumentalness         <dbl> 8.88e-03, 1.23e-01, 0.00e+00, 5.31e-0...
## $ liveness                 <dbl> 0.1500, 0.1830, 0.1190, 0.1410, 0.116...
## $ valence                  <dbl> 0.4100, 0.6940, 0.4070, 0.6520, 0.310...
## $ tempo                    <dbl> 158.003, 180.059, 144.978, 159.986, 1...
## $ track_sentiment          <fct> Turbulent/Angry, Happy/Joyful, Turbul...
## $ track.duration_ms        <int> 154251, 196583, 185566, 196000, 19438...

Artists in Top 50

artists=c()
for (i in 1:50){
  
  artists <- c(artists, track_audio_analyse_selection[[3]][[i]][[3]])
  
}
#Changing artists vector as a dataframe and sorting bypearing freaquency in top 50 music
artist_df<-as.data.frame(table(artists)) %>% arrange(desc(Freq))
head(artist_df, 15L)
##                  artists Freq
## 1                  Ezhel   16
## 2                 Ufo361   12
## 3               Ben Fero    3
## 4               Khontkar    3
## 5                 Aspova    2
## 6                   BEGE    2
## 7          Billie Eilish    2
## 8         Emir Can İğrek    2
## 9             Mert Şenel    2
## 10                Patron    2
## 11 Yüzyüzeyken Konuşuruz    2
## 12         Zeynep Bastık    2
## 13               Adamlar    1
## 14                  Ados    1
## 15                 Aga B    1

Sentiment Counts in Playlist

sent_count <- track_audio_analyse_selection %>% group_by(track_sentiment) %>% count()
sent_count
## # A tibble: 4 x 2
## # Groups:   track_sentiment [4]
##   track_sentiment     n
##   <fct>           <int>
## 1 Chill/Peaceful      2
## 2 Happy/Joyful       16
## 3 Sad/Depressing      9
## 4 Turbulent/Angry    23
ggplot(sent_count, aes(x=track_sentiment, y=n, fill=track_sentiment)) +
  geom_bar(stat="identity")

ggplot(track_audio_analyse_selection,aes(x = valence, y = energy, color = track_sentiment)) + geom_point() +
  labs(color = "", title = "Sentiment Analysis of Turkey Top 50 Chart") +
  scale_x_continuous(expand = c(0, 0), limits = c(0, 1)) + 
  scale_y_continuous(expand = c(0, 0), limits = c(0, 1)) +
  geom_label(aes(x = 0.25, y = 0.97, label = "Turbulent/Angry"), label.padding = unit(2, "mm"),  fill = "darkgrey", color="white") +
  geom_label(aes(x = 0.75, y = 0.97, label = "Happy/Joyful"), label.padding = unit(2, "mm"), fill = "darkgrey", color="white") +
  geom_label(aes(x = 0.25, y = 0.03, label = "Sad/Depressing"), label.padding = unit(2, "mm"),  fill = "darkgrey", color="white") +
  geom_label(aes(x = 0.75, y = 0.03, label = "Chill/Peaceful"), label.padding = unit(2, "mm"), fill = "darkgrey", color="white") +
  geom_segment(aes(x = 1, y = 0, xend = 1, yend = 1)) +
  geom_segment(aes(x = 0, y = 0, xend = 0, yend = 1)) +
  geom_segment(aes(x = 0, y = 0, xend = 1, yend = 0)) +
  geom_segment(aes(x = 0, y = 0.5, xend = 1, yend = 0.5)) +
  geom_segment(aes(x = 0.5, y = 0, xend = 0.5, yend = 1)) +
  geom_segment(aes(x = 0, y = 1, xend = 1, yend = 1)) 

Playlist Profile

mean_values <- turkey_top50_audio_features %>% select(danceability,energy,loudness,speechiness,acousticness,instrumentalness,liveness,valence,tempo,track.duration_ms,track.album.release_date)
mean_values<-mean_values%>%mutate(mean_danceability=mean(danceability),mean_energy=mean(energy),mean_loudness=mean(loudness),mean_speechiness=mean(speechiness),mean_acousticness=mean(acousticness),mean_instrumentalness=mean(instrumentalness),mean_liveness=mean(liveness),mean_liveness=mean(liveness),mean_valence=mean(valence),mean_tempo=mean(tempo),mean_track.duration_ms=mean(track.duration_ms))
mean_values<-mean_values[-c(1,1:11)]
mean_values<-mean_values[1,]
mean_values
##   mean_danceability mean_energy mean_loudness mean_speechiness
## 1           0.70872     0.58066      -7.82372         0.138566
##   mean_acousticness mean_instrumentalness mean_liveness mean_valence
## 1         0.2779082            0.06583722      0.136544     0.433542
##   mean_tempo mean_track.duration_ms
## 1   130.3925               215369.9

Liveness

Data type: Float
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.

Tempo

Data type: Float
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.

Danceability

Data type: Float
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.

Energy

Data type: Float
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.

Loudness

Data type: Float
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).

Speechiness

Data type: Float
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.

Acousticness

Data type: Float
A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic.

Duration_ms

Data type: int
The duration of the track in milliseconds.