Spotify is one of the largest music streaming platforms in the world. Luckily for us they have made their data available to the public via their API. With over 600 million monthly listeners we can gain valuable data on many of the worlds most popular artists such as, Adele, Drake, Dua Lipa, Eminem, & more.
Loading Packages
Using the code below you can load in the necessary packages for this tutorial. If you do not have these packages installed you will have to install them on your device first.
library('tidyverse')
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ 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('knitr')library('spotifyr')
Warning: package 'spotifyr' was built under R version 4.3.3
Input your CLIENT_ID
Retrieve you client ID from the Spotify API dashboard linked here. After clicking this link:
Log in with your Spotify account.
Go to your dashboard.
Create an app.
Give it a Name
Input a description
Enter you redirect URI, I used Spotify’s base redirect URI “http://localhost:1410/”
Make sure to check the Web API box, then click save at the bottom.
Next, go to your dashboard, then setting to obtain your client ID, insert it in the code below.
The artist_id will be the strand following “/artist/” ending before the “?” In this example it would be “4H4M0Y4cN39zIVDHvdW53x”.
Choose your Artists.
I have chosen my top five current artists for this example. Zach Bryan, Matchbox Twenty, Post Malone, Quinn XCII, & Dylan Gossett, with their corresponding artist_ids below respectively.
After choosing and enter your artist_ids into the code below, run it.
Choose the data you would like to use for your analysis.
The code below will select the data that you need for this analysis. In this example, it will be choosing, their id, name, genres, popularity, & followers.total.
Below is the code to create a pie chart to show how these artists’ popularity stack up. In this theoretical situation, if these were the only music artists to exist. This chart shows how much of the global market these artist would en-capture.
my_top_artists %>%ggplot(aes(x ="", y = popularity, fill = name, label = scales::percent(popularity/sum(popularity)))) +geom_bar(stat ="identity") +coord_polar(theta ="y") +geom_text(position =position_stack(vjust =0.5)) +labs(title ="Popularity of my Top Five Artists",fill ="Artist",x =NULL,y =NULL) +theme_void()