-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_005_analyzing-my-streaming-history.Rmd
481 lines (438 loc) · 15.1 KB
/
10_005_analyzing-my-streaming-history.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
---
title: "Analyzing my streaming history"
description: |
Identifying trends in my listening habits.
author:
- first_name: "Joshua"
last_name: "Cook"
url: https://joshuacook.netlify.app
orcid_id: 0000-0001-9815-6879
date: "`r Sys.Date()`"
output:
distill::distill_article:
toc: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, comment = "#>", dpi = 500)
library(nakedpipe)
library(magrittr)
library(ggthemes)
library(ggrepel)
library(tidyverse)
theme_set(ggthemes::theme_fivethirtyeight())
pal_538 <- deframe(ggthemes_data[["fivethirtyeight"]])
walk(list.files("lib", pattern = "R$", full.names = TRUE), source)
streaming_history <- readRDS(here::here("data", "streaming_history.rds"))
min_song_length <- 60 * 1
```
The following is a dive into my streaming history from the past year or so.
For each track, I am given the time and date, artist name, track name, and for how long the track was played.
The data was processed in [Preparing the downloaded files](05_002_spotify-raw-data-preparation.html).
---
## Time spent listening to music
To begin, we can look at the distribution of the durations of the tracks.
For reference, I have annotated the plot with 3 of my favorite songs: [*Stacy*](https://open.spotify.com/track/07ZQLYn9x4x3L3vxStc1zr?si=PKUhdcYLQXmaiyU79C-HmQ) by [Quinn XCII](https://open.spotify.com/artist/3ApUX1o6oSz321MMECyIYd?si=aBfY9yDrSmmhxe1F8ThFww), [*Good Things Fall Apart*](https://open.spotify.com/track/3LxG9HkMMFP0MZuiw3O2rF?si=T9_Hg7_pRnWRGlctI9f5aQ) by [Illenium](https://open.spotify.com/artist/45eNHdiiabvmbp4erw26rg?si=2ZdCEqJFT2KU3PZ_iB71Vw) featuring [Jon Bellion](https://open.spotify.com/artist/50JJSqHUf2RQ9xsHs0KMHg?si=2SMZIa-MS3mHU0BLmsolkg), and [*Choices*](https://open.spotify.com/track/65z28RA7Nmzsog6Noln0sB?si=suGmKtjtREmIINnBU3HrJg) by [To Kill a King](https://open.spotify.com/artist/7yHBGaYHPXkJSVUtHiM816?si=iHFiAoUHRD2xBPQc1EgPUA) (you can listen to samples of these songs at the bottom of the page).
```{r}
notable_lengths <- tibble(
song = c("Stacy", "Good Things Fall Apart", "Choices"),
length = c("2:49", "3:37", "6:28"),
x = c(169, 217, 388),
y = c(0.010, 0.010, 0.0112)
) %.% {
mutate(length = as.numeric(lubridate::ms(length)))
}
streaming_history %>%
ggplot(aes(x = sec_played)) +
geom_density(fill = pal_538["Medium Gray"], alpha = 0.7) +
geom_rect(
data = tibble(sec_played = 0),
xmin = 0, xmax = min_song_length,
ymin = 0, ymax = Inf,
fill = "grey20",
alpha = 0.2,
color = NA
) +
geom_vline(
xintercept = min_song_length,
color = "grey35",
lty = 2,
alpha = 0.8
) +
geom_vline(
aes(xintercept = length, color = song),
data = notable_lengths,
size = 1,
alpha = 0.8
) +
geom_label(
aes(label = song, x = x, y = y, color = song),
data = notable_lengths,
hjust = c(1, 0, 0),
nudge_x = c(-10, 10, 10),
alpha = 0.7,
label.size = 0,
family = "sans",
fontface = "bold"
) +
scale_x_continuous(
expand = expansion(mult = c(0, 0.02)),
limits = c(0, 600),
breaks = seq(0, 10, 2) * 60,
labels = function(x) {
round(x / 60, 1)
}
) +
scale_y_continuous(
expand = expansion(mult = c(0, 0)),
limits = c(0, 0.012)
) +
scale_color_fivethirtyeight() +
theme(
axis.title = element_text(),
legend.position = "none"
) +
labs(
x = "time spent listening to a song (min)",
y = "density",
title = "The distribution of play time",
subtitle = paste(
"Most songs were listened to for about 2-5 minutes. Some example song",
"durations are labeled. The far-left peak (highlighted in grey) represents",
"songs that were quickly skipped.",
sep = "\n"
)
)
```
The durations range from 0 to around 10 minutes.
Presumably, the short durations correspond to skipping a track at the beginning.
For the purposes of further analysis, I will set the minimum length of a song as `r round(min_song_length, 1)` seconds, removing data points with shorter durations.
The longer songs were likely background noise tracks for various wilderness albums or coffee shop sounds.
We can also see how much time I spent listening to music by plotting the cumulative duration over time.
By the gradual reduction on the slop over time, we can see that I reduced the amount of time I listened to music over the course of the year.
```{r}
streaming_history %.%
{
mutate(
cum_sec_played = cumsum(sec_played),
cum_hour_played = cum_sec_played / 60 / 60
)
} %>%
ggplot(aes(x = end_time, y = cum_hour_played)) +
geom_ribbon(
aes(ymin = 0, ymax = cum_hour_played),
alpha = 0.2,
fill = spotify_dark
) +
geom_line(size = 1, color = spotify_green) +
scale_x_datetime(
date_breaks = "2 months",
date_labels = "%b %Y",
expand = expansion(add = c(0, 0))
) +
scale_y_continuous(expand = expansion(mult = c(0, 0.02))) +
theme(
axis.title.y = element_text()
) +
labs(
y = "time (hours)",
title = "Cumulative time spent listening to Spotify"
)
```
```{r}
streaming_history %<>% filter(sec_played >= min_song_length)
```
This trend is also supported by the number of tracks I listened to per day.
The smoothened trend line indicates a lull in the fall of 2020.
```{r}
streaming_history %.%
{
mutate(date = lubridate::floor_date(end_time, "day"))
count(date)
} %>%
ggplot(aes(x = date, y = n)) +
geom_point(alpha = 0.8) +
geom_smooth(
method = "loess",
formula = "y~x",
color = spotify_green
) +
scale_x_datetime(
date_breaks = "2 months",
date_labels = "%b %Y",
expand = expansion(add = c(0, 0))
) +
theme(
axis.title.y = element_text()
) +
labs(
y = "number of songs",
title = "Daily number of songs listened to"
)
```
The variability of my listening patterns also followed the same general trend.
As the plot of the number of different artists and tracks per month below indicates, I had a peak of diversity in April and May of 2020 followed by a general decline.
```{r}
sec_axis_coef <- 2
artist_color <- pal_538[["Red"]]
track_color <- pal_538[["Blue"]]
streaming_history %.%
{
mutate(mo_year = lubridate::floor_date(end_time, "month"))
group_by(mo_year)
summarise(
num_artists = n_distinct(artist_name),
num_tracks = n_distinct(track_name)
)
ungroup()
mutate(num_tracks = num_tracks / sec_axis_coef)
} %>%
ggplot(aes(x = mo_year)) +
geom_line(aes(y = num_artists), color = artist_color, alpha = 0.7) +
geom_line(aes(y = num_tracks), color = track_color, alpha = 0.7) +
geom_point(aes(y = num_artists), color = artist_color) +
geom_point(aes(y = num_tracks), color = track_color) +
scale_y_continuous(
name = "num. artists",
sec.axis = sec_axis(~ . * sec_axis_coef, name = "num. tracks")
) +
scale_x_datetime(
date_breaks = "2 months",
date_labels = "%b %Y"
) +
theme(
axis.title.y = element_text(color = colorspace::darken(artist_color)),
axis.title.y.right = element_text(color = colorspace::darken(track_color))
) +
labs(
title = "Variability in artists and songs",
subtitle = "The number of different artists (red) and songs (blue) listened to each month."
)
```
### Favorites
Next, I want to look into who my most played artists and songs have been.
The next two plots show the top artists and individual songs from my streaming history, and the third plot shows the top songs from each of my favorite artists.
```{r}
plot_barcount <- function(df, x, y,
x_lbl, title,
nudge_text = 11,
expand_x = 0.08,
wrap_y = Inf) {
df %>%
mutate(label = scales::comma({{ x }}, accuracy = 1)) %>%
ggplot(aes(x = {{ x }}, y = {{ y }})) +
geom_text(
aes(label = label),
hjust = 0,
family = "Helvetica",
size = 3.5,
nudge_x = nudge_text
) +
scale_x_continuous(expand = expansion(c(0, expand_x))) +
scale_y_discrete(labels = scales::label_wrap(wrap_y)) +
theme_fivethirtyeight() +
theme(
panel.grid.major.y = element_blank(),
axis.title.x = element_text()
) +
labs(
x = x_lbl,
y = NULL,
title = title
)
}
streaming_history %.%
{
count(artist_name, sort = TRUE, name = "n")
head(10)
mutate(artist_name = fct_rev(fct_inorder(artist_name)))
} %>%
plot_barcount(
x = n,
y = artist_name,
x_lbl = "number of times listened",
title = "Top-10 most listened to artists",
expand_x = 0.11,
wrap_y = 30
) +
geom_col(fill = spotify_dark2, color = NA)
```
```{r}
streaming_history %.%
{
count(track_name, artist_name, sort = TRUE, name = "n")
head(10)
mutate(track_name = fct_rev(fct_inorder(track_name)))
} %>%
plot_barcount(
x = n,
y = track_name,
x_lbl = "number of times listened",
title = "Top-10 most listened to songs",
nudge_text = 2,
expand_x = 0.06,
wrap_y = 30
) +
geom_col(aes(fill = artist_name), color = NA) +
scale_fill_excel_new(
"Atlas",
labels = function(x) {
str_wrap(x, width = 25)
},
guide = guide_legend(nrow = 1, title = "Artist")
) +
theme(
legend.margin = margin(),
legend.title = element_text(size = 11),
legend.key.size = unit(4, "mm")
)
```
Interestingly, my top songs are dominated by [Jon Bellion](https://open.spotify.com/artist/50JJSqHUf2RQ9xsHs0KMHg?si=2SMZIa-MS3mHU0BLmsolkg) though my most played artist was [Imagine Dragons](https://open.spotify.com/artist/53XhwfbYqKCa1cC15pYq2q?si=GcRvAHkmTCuCChoe1nJULA).
This likely indicates that I listened to many different songs from [Imagine Dragons](https://open.spotify.com/artist/53XhwfbYqKCa1cC15pYq2q?si=GcRvAHkmTCuCChoe1nJULA) while I tended to listen to fewer [Jon Bellion](https://open.spotify.com/artist/50JJSqHUf2RQ9xsHs0KMHg?si=2SMZIa-MS3mHU0BLmsolkg) songs very frequently.
```{r, fig.height=6}
ignore_top_artists <- c(
"Background Noise From TraxLab", "Ambient Sounds from I'm In Records"
)
top_artists <- streaming_history %.% {
filter(!artist_name %in% !!ignore_top_artists)
count(artist_name, sort = TRUE)
head(6)
pull(artist_name)
unlist()
unique()
}
streaming_history %.%
{
filter(artist_name %in% !!top_artists)
group_by(artist_name)
count(track_name, sort = TRUE)
slice(1:5)
ungroup()
mutate(track_name = fct_rev(fct_inorder(track_name)))
} %>%
plot_barcount(
x = n,
y = track_name,
x_lbl = "number of times listened",
title = "Top songs of my favorite artists",
nudge_text = 3,
expand_x = 0.20,
wrap_y = 30
) +
geom_col(fill = spotify_dark2, color = NA) +
facet_wrap(~artist_name, ncol = 2, scales = "free") +
theme(strip.text = element_text(face = "bold"))
```
Plotting the number of times I listened to my top songs in each month, [*Good Things Fall Apart*](https://open.spotify.com/track/3LxG9HkMMFP0MZuiw3O2rF?si=uY4xje_uSi24UUAB21wcbg) (orange) peaked in February, probably after I first discovered it in late January.
Then, In April, I got hooked on [*Pre-Occupied*](https://open.spotify.com/track/0i4Zkb6Ts5JqLJIAMNzSSl?si=Tz9423Y9ThSfHQK5UBcJkA) by [Jon Bellion](https://open.spotify.com/artist/50JJSqHUf2RQ9xsHs0KMHg?si=iURyF8AzTCOL86CmmGnJ3w) (purple).
```{r}
top_songs <- streaming_history %.% {
count(artist_name, track_name, sort = TRUE)
head(6)
select(track_name, artist_name)
}
streaming_history %.%
{
mutate(date = lubridate::floor_date(end_time, unit = "month"))
count(date, artist_name, track_name)
right_join(top_songs, by = c("track_name", "artist_name"))
} %>%
ggplot(aes(x = date, y = n, color = track_name)) +
geom_line() +
geom_point() +
scale_color_excel_new(
"Atlas",
labels = function(x) {
str_wrap(x, width = 25)
},
guide = guide_legend(nrow = 2, title = NULL)
) +
scale_x_datetime(date_breaks = "2 months", date_labels = "%b %Y") +
labs(
title = "The frequency of my top songs over time",
subtitle = "The number of times each song was played per month."
)
```
Below is a similar plot but showing how often I listened to my favorite artists each month.
```{r, fig.height=10}
pal <- c(excel_new_pal("Atlas")(6), "other" = pal_538[["Dark Gray"]])
streaming_history %.%
{
mutate(
artist_name = fct_other(artist_name, keep = top_artists, other_level = "other"),
date = lubridate::floor_date(end_time, "week")
)
count(artist_name, date, name = "n")
} %>%
ggplot(aes(x = date, y = n, color = artist_name)) +
facet_wrap(artist_name ~ ., scales = "free_y", ncol = 1) +
geom_col(
aes(color = artist_name, fill = artist_name),
position = "dodge",
alpha = 0.5
) +
geom_smooth(
method = "loess",
formula = "y~x",
alpha = 0.7,
se = FALSE,
span = 0.5
) +
scale_color_manual(values = pal) +
scale_fill_manual(values = pal) +
theme(
strip.text = element_text(face = "bold"),
legend.position = "none"
) +
labs(
title = "Trends in listening to my favorite artists"
)
```
Most artists followed the general trend of more listening early in the year, trailing off in the Fall.
This was no true, however, for [Quinn XCII](https://open.spotify.com/artist/3ApUX1o6oSz321MMECyIYd?si=xNmBqLMsQ0KtNDonz6Jy3w) ([pronounced "Quinn 92"](https://en.wikipedia.org/wiki/Quinn_XCII#2020-present:_A_Letter_to_My_Younger_Self)) because he dropped a new album, [*A Letter To My Younger Self*](https://open.spotify.com/album/1dVw3jSdgZp7PfGhCEo32t?si=TOsNYpa2Txm4BwO6pZD7OQ), on July 10, 2020.
You can see this switch in the following plot of which Quinn XCII songs I listened to most.
In July, there was a spike in the total number of Quinn XCII songs played, and the top individual song switched to [*Notice Me*](https://open.spotify.com/track/6mVzv4E4oc7Fcw6yUTfzub?si=FVP-1x8QQSCqrc1A3UYqQw) (yellow).
```{r}
pal <- c(excel_new_pal("Office Theme")(6), "other" = pal_538[["Medium Gray"]])
streaming_history %.%
{
filter(artist_name == "Quinn XCII")
mutate(
track_name = fct_lump_n(
track_name,
n = length(pal) - 1,
other_level = "other"
),
date = lubridate::floor_date(end_time, "month"),
)
count(date, track_name)
} %>%
ggplot(
aes(x = date, y = n, color = track_name, fill = track_name)
) +
geom_col(position = "stack") +
scale_color_manual(
values = pal
) +
scale_fill_manual(
values = pal
) +
scale_x_datetime(
date_breaks = "2 months",
date_labels = "%b %Y",
expand = expansion(add = c(0, 0))
) +
theme(
legend.position = "top",
legend.key.size = unit(0.5, "cm"),
) +
labs(
y = "times listened",
color = NULL,
fill = NULL,
title = "Trend of favorite songs by Quinn XCII"
)
```
---
<iframe src="https://open.spotify.com/embed/track/1pyGo7knT3LE2I1FJIrwdX" width="100" height="100" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
<iframe src="https://open.spotify.com/embed/track/3LxG9HkMMFP0MZuiw3O2rF" width="100" height="100" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
<iframe src="https://open.spotify.com/embed/track/65z28RA7Nmzsog6Noln0sB" width="100" height="100" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>