-
Notifications
You must be signed in to change notification settings - Fork 0
/
italianRapSong.Rmd
377 lines (319 loc) · 9.86 KB
/
italianRapSong.Rmd
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
---
title: "Spotify italian rap"
author: "Giovanni Esposito"
output:
revealjs::revealjs_presentation:
theme: moon
highlight: haddock
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
# cache results
knitr::opts_chunk$set(
cache = TRUE,
echo = TRUE,
eval = TRUE,
message = FALSE,
warning = FALSE,
fig.align = 'center'
)
```
```{r library, include=FALSE}
library(tidyverse)
library(ggplot2)
library(plotly)
library(gapminder)
library(gridExtra)
library(grid)
library(reshape2)
library(RColorBrewer)
library(scales)
```
## Dataset
<h3>
Dataset was created use https://github.com/gioggi/SpotifyScarper.<br/>
Dataset is update to april 2021. <br/>
about 160 Artists<br/>
about 11.5k Tracks
</h3>
<hr/>
<h4>
<b>Key helper</b>:<br/>
<b>Popularity</b>: Measure the popularity based on play number of the track <br/>
<b>Valence</b>: a measure of happiness <br/>
<b>Liveness</b>: detects the presence of an audience in the recording. <br/>
<b>Speechiness</b>: Detects the presence of spoken words in a track. <br/>
<b>Energy</b>: represents a perceptual measure of intensity and activity. <br/>
<b>Danceability</b>: describes how suitable a track is for dancing based <br/>
</h4>
```{r dataset, message=FALSE, echo=FALSE}
# put artist and into a data frame and columns mapping
artists = read_csv("/home/gioggi/Documents/ItalianRapSong/data/artist210421.csv")
artists_mapped = rename(
artists,
"artist_id" = "Id",
"artist_name" = "Name",
"artist_popularity" = "Popularity",
"artist_followers" = "Followers",
"artist_geners" = "Generes"
)
artist_color <- rainbow(nrow(artists_mapped))
artists_mapped = cbind(artists_mapped, artist_color)
# put track and into a data frame
tracks = read_csv("/home/gioggi/Documents/ItalianRapSong/data/track210421.csv") %>%
group_by(Id)
tracks$album_release_date <-
as.Date(tracks$album_release_date, '%Y')
# left join between tracks and artists
# merge( x= tracks, y = artists_mapped, by = "artist_id", all.x = TRUE, fill=-9999)
```
## How are the 50 more popular italian rap artist now for Spotify?
```{r artist by popularity, message=FALSE, echo=FALSE}
# order artist by popularity
popular_artists = head(artists_mapped[order(artists_mapped$artist_popularity, decreasing = T),], n = 50)
# chart
ggplot(data = popular_artists, aes(x = artist_popularity, y = reorder(artist_name, artist_popularity))) +
geom_bar(stat = "identity", fill = popular_artists$artist_color) +
theme_dark() +
theme(
axis.line = element_blank(),
axis.title.y = element_blank()
) +
xlab('Artist popularity')
```
## How are the 50 more followed italian rap artist now for Spotify?
```{r artist by followers, message=FALSE, echo=FALSE}
# order artist by followers
followest_artists = head(artists_mapped[order(artists_mapped$artist_followers, decreasing = T), ], n = 50)
# chart
ggplot(data = followest_artists, aes(x = artist_followers, y = reorder(artist_name, artist_followers))) +
geom_bar(stat = "identity", fill = followest_artists$artist_color) +
theme_dark() +
theme(
axis.line = element_blank(),
axis.title.y = element_blank()
)+
xlab('Number of followers')
```
# Matched popularity and followers for top 50 artists!
```{css, echo=FALSE}
.slides {
zoom: 1 !important;
}
```
```{r match popularity and followers, message=FALSE, echo=FALSE}
artist_songs_number = merge(
x = tracks,
y = popular_artists,
by = "artist_id",
all.x = FALSE,
fill = -9999
) %>%
count(artist_id, name = "n_songs")
artist_sum_popularity = merge(
x = tracks,
y = popular_artists,
by = "artist_id",
all.x = FALSE,
fill = -9999
) %>%
group_by(artist_id) %>%
summarise(tot_popularity = sum(popularity))
top_artists = merge(
x = artist_songs_number,
y = popular_artists,
by = "artist_id",
all.x = FALSE,
fill = -9999
)
top_artists = merge(
x = artist_sum_popularity,
y = top_artists,
by = "artist_id",
all.x = FALSE,
fill = -9999
)
p <- top_artists %>%
ggplot(aes(tot_popularity, artist_followers, size = n_songs, color=artist_color, label=artist_name),x.title="aw") +
geom_point() +
theme_dark() +
theme(legend.position='none') +
xlab('Total popularity')
ggplotly(p,tooltip = c("artist_name","n_songs","artist_followers","tot_popularity"))
```
## Matched average popularity and followers for top 50 artists!
```{r match popularity and followers with average, message=FALSE, echo=FALSE}
top_artists['average_popularity'] = top_artists['tot_popularity'] / top_artists['n_songs']
p <- top_artists %>%
ggplot(aes(average_popularity, artist_followers, size = n_songs, color=artist_color, label=artist_name),x.title="aw") +
geom_point() +
theme_dark() +
theme(legend.position='none') +
xlab('Average popularity')
ggplotly(p,tooltip = c("artist_name","n_songs","artist_followers","tot_popularity"))
```
# The stats for all songs by Spotify!
```{r point stats, message=FALSE, echo=FALSE}
danceability <-
ggplot(tracks, aes(x = popularity, y = danceability)) +
geom_point(color = "purple", alpha = 0.2) +
geom_smooth(se = FALSE) +
theme_dark()+
xlab('Popularity')+
ylab('Danceability')
energy <- ggplot(tracks, aes(x = popularity, y = energy)) +
geom_point(color = "red", alpha = 0.2) +
geom_smooth(se = FALSE) +
theme_dark() +
xlab('Popularity')+
ylab('Energy')
speechiness <-
ggplot(tracks, aes(x = popularity, y = speechiness)) +
geom_point(color = "lightblue", alpha = 0.2) +
geom_smooth(se = FALSE) +
theme_dark()+
xlab('Popularity')+
ylab('Speechiness')
liveness <- ggplot(tracks, aes(x = popularity, y = liveness)) +
geom_point(color = "green", alpha = 0.2) +
geom_smooth(se = FALSE) +
theme_dark()+
xlab('Popularity')+
ylab('Liveness')
valence <- ggplot(tracks, aes(x = popularity, y = valence)) +
geom_point(color = "blue", alpha = 0.2) +
geom_smooth(se = FALSE) +
theme_dark()+
xlab('Popularity')+
ylab('Valence')
duration_ms <-
ggplot(tracks, aes(x = popularity, y = duration_ms)) +
geom_point(color = "orange", alpha = 0.2) +
geom_smooth(se = FALSE) +
theme_dark()+
xlab('Popularity')+
ylab('Duration ms')
grid.arrange(danceability,
energy,
speechiness,
liveness,
valence,
duration_ms)
```
## Spotify stats for top 200 popular tracks!
```{r boxplot stats top 200 populars, message=FALSE, echo=FALSE}
top_200_popular_tracks = head(tracks[order(tracks$popularity, decreasing = T), ], n = 200)
top_danceability <-
ggplot(top_200_popular_tracks, aes(x = popularity, y = danceability)) +
geom_boxplot(fill = "purple") +
theme_dark() +
xlab('Popularity')+
ylab('Danceability')
top_energy <-
ggplot(top_200_popular_tracks, aes(x = popularity, y = energy)) +
geom_boxplot(fill = "red") +
theme_dark() +
xlab('Popularity')+
ylab('Energy')
top_speechiness <-
ggplot(top_200_popular_tracks, aes(x = popularity, y = speechiness)) +
geom_boxplot(fill = "lightblue") +
theme_dark() +
xlab('Popularity')+
ylab('Speechiness')
top_liveness <-
ggplot(top_200_popular_tracks, aes(x = popularity, y = liveness)) +
geom_boxplot(fill = "green") +
theme_dark() +
xlab('Popularity')+
ylab('Liveness')
top_valence <-
ggplot(top_200_popular_tracks, aes(x = popularity, y = valence)) +
geom_boxplot(fill = "blue") +
theme_dark() +
xlab('Popularity')+
ylab('Valence')
top_duration_ms <-
ggplot(top_200_popular_tracks, aes(x = popularity, y = duration_ms)) +
geom_boxplot(fill = "orange") +
theme_dark()+
xlab('Popularity')+
ylab('Duration ms')
grid.arrange(
top_danceability,
top_energy,
top_speechiness,
top_liveness,
top_valence,
top_duration_ms
)
```
# Spotify median stats in the time!
```{r stats by date, message=FALSE, echo=FALSE}
year_median_danceability = tracks %>%
group_by(album_release_date) %>%
summarise(median_danceability = mean(danceability))
year_median_danceability_charts <-
ggplot(year_median_danceability,
aes( album_release_date, median_danceability)) +
geom_line(color = "purple", size = 1.2) +
theme_dark()+
xlab('Album release date')+
ylab('Danceability')
year_median_energy = tracks %>%
group_by(album_release_date) %>%
summarise(median_energy = mean(energy))
year_median_energy_charts <-
ggplot(year_median_energy, aes( album_release_date, median_energy)) +
geom_line(color = "red", size = 1.2) +
theme_dark()+
xlab('Album release date')+
ylab('Energy')
year_median_speechiness = tracks %>%
group_by(album_release_date) %>%
summarise(median_speechiness = mean(speechiness))
year_median_speechiness_charts <-
ggplot(year_median_speechiness,
aes(album_release_date,median_speechiness)) +
geom_line(color = "lightblue", size = 1.2) +
theme_dark()+
xlab('Album release date')+
ylab('Speechiness')
year_median_liveness = tracks %>%
group_by(album_release_date) %>%
summarise(median_liveness = mean(liveness))
year_median_liveness_charts <-
ggplot(year_median_liveness, aes(album_release_date, median_liveness)) +
geom_line(color = "green", size = 1.2) +
theme_dark()+
xlab('Album release date')+
ylab('Liveness')
year_median_valence = tracks %>%
group_by(album_release_date) %>%
summarise(median_valence = mean(valence))
year_median_valence_charts <-
ggplot(year_median_valence, aes(album_release_date,median_valence)) +
geom_line(color = "blue", size = 1.2) +
theme_dark()+
xlab('Album release date')+
ylab('Valence')
year_median_duration_ms = tracks %>%
group_by(album_release_date) %>%
summarise(median_duration_ms = mean(duration_ms))
year_median_duration_ms_charts <-
ggplot(year_median_duration_ms,
aes(album_release_date, median_duration_ms)) +
geom_line(color = "orange", size = 1.2) +
theme_dark()+
xlab('Album release date')+
ylab('Duration ms')
grid.arrange(
year_median_danceability_charts,
year_median_energy_charts,
year_median_speechiness_charts,
year_median_liveness_charts,
year_median_valence_charts,
year_median_duration_ms_charts
)
```