Created
August 11, 2018 00:46
-
-
Save beemyfriend/ec57ee88dcf409e14cd3f1b78e0190f3 to your computer and use it in GitHub Desktop.
Playing with Spotify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages('spotifyr') | |
library(spotifyr) | |
library(tidyverse) | |
library(httr) | |
Sys.setenv(SPOTIFY_CLIENT_ID = "NOT_TELLING") | |
Sys.setenv(SPOTIFY_CLIENT_SECRET = "NOT_TELLING") | |
spotify_df <- get_artist_audio_features('linkin park') | |
write_csv(spotify_df, 'linkin_park_spotify.csv') | |
spotify_df <- spotify_df %>% | |
filter(album_name %in% c("Hybrid Theory", | |
"Meteora", | |
"Minutes To Midnight", | |
"A Thousand Suns", | |
"LIVING THINGS", | |
"The Hunting Party", | |
"One More Light")) | |
polar_spotify <- spotify_df %>% | |
mutate(date = album_release_date %>% | |
str_extract('(?<=^\\d{2})\\d{2}') %>% | |
{paste0("'", .)} , | |
album_name = album_name %>% | |
str_to_title() %>% | |
{paste0(., ' | ', date)}) %>% | |
select(album_name, | |
track_name, | |
danceability, | |
energy, | |
loudness, | |
speechiness, | |
acousticness, | |
valence, | |
instrumentalness, | |
tempo) %>% | |
mutate(loudness = (loudness + 60 )/ 60, | |
tempo = tempo/200, | |
end = danceability) %>% | |
gather(key = key, value = value, -album_name, -track_name) %>% | |
mutate(key = factor(key, levels = unique(key)), | |
angle = as.numeric(key)/length(unique(key)) * 2 * pi, | |
album_name = factor(album_name, levels = unique(album_name))) | |
cairo_pdf('linkin_park_discography.pdf', width = 14, height = 8) | |
png('linkin_park_discography.png', width = 800, 600) | |
ggplot(polar_spotify, aes(x = angle, | |
y = value, | |
group = track_name)) + | |
geom_point() + | |
scale_x_continuous(breaks = unique(polar_spotify$angle) %>% .[-length(.)], | |
labels = levels(polar_spotify$key) %>% .[-length(.)], | |
name = '', | |
minor_breaks = NULL) + | |
scale_y_continuous(name = '') + | |
coord_polar(theta = 'x') + | |
geom_path() + | |
theme_bw() + | |
theme(axis.text.x = element_text(angle = seq(0, -315, by = -45), | |
size = 7)) + | |
facet_wrap(~album_name) + | |
labs(title = "Linkin Park | Studio Albums", | |
subtitle = "Spotify Metrics") | |
dev.off() | |
spotify_df_gaga <- get_artist_audio_features('lady gaga') | |
write_csv(spotify_df_gaga, 'lady_gaga_spotify.csv') | |
polar_spotify_gaga <- spotify_df_gaga %>% | |
filter(album_name %in% c("The Fame", | |
"The Fame Monster (Explicit Version)", | |
"Born This Way", | |
"ARTPOP", | |
"Joanne")) %>% | |
mutate(date = album_release_date %>% | |
str_extract('(?<=^\\d{2})\\d{2}') %>% | |
{paste0("'", .)} , | |
album_name = album_name %>% | |
str_to_title() %>% | |
{paste0(., ' | ', date)}) %>% | |
select(album_name, | |
track_name, | |
danceability, | |
energy, | |
loudness, | |
speechiness, | |
acousticness, | |
valence, | |
instrumentalness, | |
tempo) %>% | |
mutate(loudness = (loudness + 60 )/ 60, | |
tempo = tempo/200, | |
end = danceability) %>% | |
gather(key = key, value = value, -album_name, -track_name) %>% | |
mutate(key = factor(key, levels = unique(key)), | |
angle = as.numeric(key)/length(unique(key)) * 2 * pi, | |
album_name = factor(album_name, levels = unique(album_name))) | |
cairo_pdf('lady_gaga_discography.pdf', width = 14, height = 8) | |
png('lady_gaga_discography.png', width = 800, height = 600) | |
ggplot(polar_spotify_gaga, aes(x = angle, | |
y = value, | |
group = track_name)) + | |
geom_point() + | |
scale_x_continuous(breaks = unique(polar_spotify$angle) %>% .[-length(.)], | |
labels = levels(polar_spotify$key) %>% .[-length(.)], | |
name = '', | |
minor_breaks = NULL) + | |
scale_y_continuous(name = '') + | |
coord_polar(theta = 'x') + | |
geom_path() + | |
theme_bw() + | |
theme(axis.text.x = element_text(angle = seq(0, -315, by = -45), | |
size = 7)) + | |
facet_wrap(~album_name) + | |
labs(title = "Lady Gaga | Studio Albums", | |
subtitle = "Spotify Metrics") | |
dev.off() | |
spotify_df_talking_heads <- get_artist_audio_features('talking heads') | |
write_csv(spotify_df_talking_heads, 'talking_heads_spotify.csv') | |
polar_spotify_talking_heads <- spotify_df_talking_heads %>% | |
filter(album_name %in% c("Talking Heads 77" , | |
"More Songs About Buildings And Food" , | |
"Fear Of Music", | |
"Remain In Light", | |
"The Name Of This Band Is Talking Heads (Expanded & Remastered)", | |
"Speaking In Tongues", | |
"Stop Making Sense", | |
"Little Creatures", | |
"True Stories", | |
"Naked")) %>% | |
mutate(date = album_release_date %>% | |
str_extract('(?<=^\\d{2})\\d{2}') %>% | |
{paste0("'", .)} , | |
album_name = album_name %>% | |
str_to_title() %>% | |
{paste0(., '\n', date)}) %>% | |
select(album_name, | |
track_name, | |
danceability, | |
energy, | |
loudness, | |
speechiness, | |
acousticness, | |
valence, | |
instrumentalness, | |
tempo) %>% | |
mutate(loudness = (loudness + 60 )/ 60, | |
tempo = tempo/200, | |
end = danceability) %>% | |
gather(key = key, value = value, -album_name, -track_name) %>% | |
mutate(key = factor(key, levels = unique(key)), | |
angle = as.numeric(key)/length(unique(key)) * 2 * pi, | |
album_name = factor(album_name, levels = unique(album_name))) | |
cairo_pdf('talking_heads_discography.pdf', width = 14, height = 8) | |
png('talking_heads_discography.png', width = 800, height = 600) | |
ggplot(polar_spotify_talking_heads, aes(x = angle, | |
y = value, | |
group = track_name)) + | |
geom_point() + | |
scale_x_continuous(breaks = unique(polar_spotify$angle) %>% .[-length(.)], | |
labels = levels(polar_spotify$key) %>% .[-length(.)], | |
name = '', | |
minor_breaks = NULL) + | |
scale_y_continuous(name = '') + | |
coord_polar(theta = 'x') + | |
geom_path() + | |
theme_bw() + | |
theme(axis.text.x = element_text(angle = seq(0, -315, by = -45), | |
size = 7), | |
strip.text = element_text(size=5)) + | |
facet_wrap(~album_name) + | |
labs(title = "Taking Heads | Studio & Live Albums", | |
subtitle = "Spotify Metrics") | |
dev.off() | |
spotify_df_britney_spears <- get_artist_audio_features('britney spears') | |
write_csv(spotify_df_britney_spears, 'britney_spears_spotify.csv') | |
polar_spotify_britney_spears <- spotify_df_britney_spears %>% | |
filter(album_name %in% c("...Baby One More Time (Digital Deluxe Version)" , | |
"Oops!... I Did It Again" , | |
"Britney (Digital Deluxe Version)" , | |
"In The Zone", | |
"Blackout", | |
"Circus (Deluxe Version)", | |
"Femme Fatale (Deluxe Version)", | |
"Britney Jean (Deluxe Version)", | |
"Glory (Deluxe Version)")) %>% | |
mutate(date = album_release_date %>% | |
str_extract('(?<=^\\d{2})\\d{2}') %>% | |
{paste0("'", .)} , | |
album_name = album_name %>% | |
str_to_title() %>% | |
{paste0(., '\n', date)}) %>% | |
select(album_name, | |
track_name, | |
danceability, | |
energy, | |
loudness, | |
speechiness, | |
acousticness, | |
valence, | |
instrumentalness, | |
tempo) %>% | |
mutate(loudness = (loudness + 60 )/ 60, | |
tempo = tempo/200, | |
end = danceability) %>% | |
gather(key = key, value = value, -album_name, -track_name) %>% | |
mutate(key = factor(key, levels = unique(key)), | |
angle = as.numeric(key)/length(unique(key)) * 2 * pi, | |
album_name = factor(album_name, levels = unique(album_name))) | |
cairo_pdf('talking_heads_discography.pdf', width = 14, height = 8) | |
png('britney_spears_discography.png', width = 800, height = 600) | |
ggplot(polar_spotify_britney_spears, aes(x = angle, | |
y = value, | |
group = track_name)) + | |
geom_point() + | |
scale_x_continuous(breaks = unique(polar_spotify$angle) %>% .[-length(.)], | |
labels = levels(polar_spotify$key) %>% .[-length(.)], | |
name = '', | |
minor_breaks = NULL) + | |
scale_y_continuous(name = '') + | |
coord_polar(theta = 'x') + | |
geom_path() + | |
theme_bw() + | |
theme(axis.text.x = element_text(angle = seq(0, -315, by = -45), | |
size = 7), | |
strip.text = element_text(size=5)) + | |
facet_wrap(~album_name) + | |
labs(title = "Britney Spears | Studio Albums", | |
subtitle = "Spotify Metrics") | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment