-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartists_development.R
61 lines (40 loc) · 1.85 KB
/
artists_development.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Analyzing Artists development
#----------------------------------------------------------------------------------------
# Set up
#----------------------------------------------------------------------------------------
#install.packages('spotifyr')
library(spotifyr)
library(tidyverse)
library(knitr)
library(dplyr)
#devtools::install_github("ricardo-bion/ggradar")
library(ggradar)
library(scales)
library(ggplot2)
library(ggiraphExtra)
library(ggRadar)
Sys.setenv(SPOTIFY_CLIENT_ID = '531568209321426ba50d24e911b23c80')
Sys.setenv(SPOTIFY_CLIENT_SECRET = 'd4307d3c67c74598bed9d7d80f4db35b')
access_token <- get_spotify_access_token()
#----------------------------------------------------------------------------------------
# Kendrick Lamar
#----------------------------------------------------------------------------------------
kendrick <- get_artist_audio_features('kendrick lamar')
# get data ready for radar chart
# make a vector of the features we want to plot
radar_features <- c("album_name", "danceability", "energy", "loudness",
"speechiness", "acousticness", "instrumentalness", "liveness", "valence", "tempo")
kendrick_radar <- kendrick[,radar_features]
kendrick_radar_agg <- aggregate(kendrick_radar, by=list(kendrick_radar$album_name), FUN = 'mean')
kendrick_radar_agg <- select(kendrick_radar_agg, -2)
kendrick_radar_agg <- kendrick_radar_agg[-c(3, 5), ]
kendrick_radar_agg$Group.1[1]="Black Panther"
kendrick_radar_agg %>%
mutate(across(c(2:9), as.numeric)) %>%
mutate_each(funs(rescale), -Group.1) %>%
ggradar()+
scale_color_manual(values=c("grey3", "red4", "grey32", "gray1",
"goldenrod4", "mistyrose4", "darkolivegreen"))+
theme(legend.position = "right")
# need to improve this! make the polygons filled, I can't do this with ggradar
# but I can try with ggplot geom plygon and radar shape