Hello & Welcome !
Today, I will be running through a tutorial of how to use the package “spotifyr.” To start, all reading this should know I am not the average spotify user, I do not like listening to music. Therefore, this shall be extremely interesting to see what comes up. I walk you through downloading the data and some functions for music lovers! And you will see how my music options make no sense what-so-ever
Below I will show you what I did first to setup my project:
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(fig.width=12, fig.height=8)
library(spotifyr)
library(knitr)
library(tidyverse)
library(lubridate)Then, I found my personal spodify information which i will not disclose but I can disclose a similar function on how to do it without my personal data.
Sys.setenv(SPOTIFY_CLIENT_ID = INSERT YOUR ID)
Sys.setenv(SPOTIFY_CLIENT_SECRET = INSERT YOUR SECRET CODE)
access_token <- get_spotify_access_token()
id <- “INSERT ID AGAIN”
Now that you can look at your data now that its loaded in!
As I mentioned, I am not a music person, so I wanted to see my 5 most recently played songs. I genuinely do not know any of these songs listed below; however, I guess they are my most recently played. I will also show how I got this table below”
get_my_recently_played(limit = 5) %>%
mutate(artist.name = map_chr(track.artists, function(x) x$name[1])) %>%
select(track.name, artist.name, track.album.name) %>%
kable()| track.name | artist.name | track.album.name |
|---|---|---|
| Sweetest Pie | Megan Thee Stallion | Sweetest Pie |
| Need to Know | Doja Cat | Planet Her |
| THATS WHAT I WANT | Lil Nas X | MONTERO |
| Sigue | J Balvin | Sigue/Forever My Love |
| Cold Heart - PNAU Remix | Elton John | Cold Heart (PNAU Remix) |
Next, I thought hmm what are my top artist lets see if I know any of this data, again I will report the code as well as the graph:
get_my_top_artists_or_tracks(type = 'artists', time_range = 'long_term', limit = 5) %>%
select(name, genres) %>%
kable()| name | genres |
|---|---|
| Kidz Bop Kids | children’s music |
| Ed Sheeran | pop , uk pop |
| The Chainsmokers | dance pop , edm , electropop , pop , pop dance , tropical house |
| Bazzi | dance pop , electropop, pop |
| Lizzo | dance pop , escape room , minnesota hip hop, pop , trap queen |
Now, these I actually knew. Kids bop is what I would always played while I did nanny so that checks out. I went to a Chain smokers concert sophomore year with my friends and I wanted to actually know the songs and not be left out, so that also makes sense. I think you all can see I actually recognize this set of artists.
As you can see it is super simple to find this data (and I was able to verify it based on my basic knowledge of my listening history). From here you can build graphs, and really dig into different aspects of the beats and different interesting levels of a song. Here is a basic tutorial of how to use “spotifyr”.