-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR_project_main.Rmd
899 lines (657 loc) · 25.9 KB
/
R_project_main.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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
---
title: "Analiza muzycznych platform streamingowych"
author: "Jakub Piasek"
output:
prettydoc::html_pretty:
theme: hpstr
toc: true
css: styles.css
---
# Opis projektu
Celem tej analizy jest zbadanie różnic w bazie słuchaczy trzech serwisów streamingowych, jakimi są Spotify, Apple Music oraz YouTube. Różnice w najbardziej słuchanych gatunkach, artystach oraz piosenkach.
Dodatkowo dla porównania jest również analizowany serwis iTunes, który tak jak Apple Music jest produktem firmy Apple. iTunes służy jako biblioteka multimediów, odtwarzacz multimediów oraz radio. Powód dla którego został również tutaj zawarty to fakt, że przez wiele lat był głównym wyznacznikiem cyfrowej sprzedaży muzyki. Teraz w erze streamingu ta platforma nie jest aż tak powszechnie używana, więc służy za kontrast uzupełniający trudno dostępne statystki Apple Music.
[Repozytorium na GitHub](https://github.com/sand194/music_dsp.git)
```{r cache=FALSE, echo=FALSE, results=FALSE, warning=FALSE}
# Managing project dependencies
library(packrat)
# packrat::unbundle("packrat/bundles/music_dsp-2024-06-08.tar.gz", "packrat")
```
### Ładowanie potrzebnych bibliotek
```{r dependencies, warning=FALSE,message=FALSE,error=FALSE, results='hide'}
library(tidyverse)
library(lintr)
library(ggthemes)
library(ggrepel)
library(plotly)
library(fuzzyjoin)
library(flextable)
library(webshot)
library(htmltools)
```
# Źródło danych
Dane pobrałem ze strony [kworb.net](https://kworb.net/) i jej wielu podstron. Jest to strona autora o nicku kworb. W łatwy sposób udostępnia on na niej różne statystki dotyczące tego jak radzi sobie branża muzyczna na serwisach streamingowych.
Statystyki dla najbardziej streamowanych piosenek na Spotify zostały wzięte z [Wikipedii](https://en.wikipedia.org/wiki/List_of_Spotify_streaming_records), ponieważ na stronie [kworb.net](https://kworb.net/) nie zostały one udostępnione.
Aby uzyskać metadane dotyczące gatunków w jakim piosenki oraz artyści wykonują, użyłem zestawu danych danych [MusicOSet](https://marianaossilva.github.io/DSW2019/).
# Data pipeline
Pipeline, którego użyłem do pozyskania danych oraz ich wczesnej technicznej obróbki.
Linijki z komendą `source()` służyły mi podczas pracy, aby połączyć całą strukturę plików w repozytorium do jednego głównego pliku `.Rmd`. Niektóre są zakomentowane, ponieważ nie są potrzebne do eksportu reportu.
## Web scraping
Sposób w jaki pobrałem dane ze strony [kworb.net](https://kworb.net/) oraz [Wikipedii](https://en.wikipedia.org/wiki/List_of_Spotify_streaming_records).
```{r scraping_source}
knitr::read_chunk('scraping.R')
# source("scraping.R", echo = F, local = knitr::knit_global())
```
- Plik źródłowy scrapowania danych
```{r, echo=FALSE, results='asis'}
code <- readLines("scraping.R")
cat("```r\n")
cat(code, sep = "\n")
cat("\n```")
```
## Export danych
Po scrapowaniu wyeksportowałem je do plików `.csv`, aby mieć je lokalnie zapisane w repozytorium. Ułatwia to uruchamianie projektu oraz zapobiega zmianie danych.
```{r, eval = FALSE}
knitr::read_chunk('data_export.R')
# source("data_export.R", echo = F, local = knitr::knit_global())
```
- Plik źródłowy exportu danych
```{r, echo=FALSE, results='asis'}
code <- readLines("data_export.R")
cat("```r\n")
cat(code, sep = "\n")
cat("\n```")
```
## Import danych
Import surowych danych, które zostały na samym początku zescrapowane.
```{r, warning=FALSE, warning=FALSE, message=FALSE}
source("data_import.R", echo = F, local = knitr::knit_global())
knitr::read_chunk('data_import.R')
```
- Plik źródłowy importu danych
```{r data_import.R, eval=FALSE, warning=FALSE, message=FALSE}
```
Ilość rekordów we wszystkich ramkach danych:
```{r}
all_objects <- ls()
data_frame_objects <- all_objects[sapply(all_objects, function(x) is.data.frame(get(x)))]
row_counts <- sapply(data_frame_objects, function(x) nrow(get(x)))
total_rows <- sum(row_counts)
total_rows
total_rows > 30000
```
## Czyszczenie danych
Dopuściłem się wstępnej obróbki surowo zescrapowanych danych, aby usunąć zduplikowane, bądź niepotrzebne kolumny i wiersze.
```{r data_cleaning}
knitr::read_chunk('cleaning.R')
source("cleaning.R", echo = F, local = knitr::knit_global())
```
- Plik źródłowy czyszczenia danych
```{r cleaning.R, eval=FALSE}
```
## Funkcje do wizualizacji
Przed utworzeniem konkretnych wizualizacji stworzyłem osobne funkcje, których używałem do stworzenia wielu podobnych wykresów, aby uniknąć redundancji w kodzie.
```{r plots, warning=FALSE, message=FALSE}
knitr::read_chunk('plots.R')
source("plots.R", echo = F, local = knitr::knit_global())
```
- Plik źródłowy tworzenia wykresów
```{r plots.R, eval=FALSE}
```
## Kustomizacja motywów
Aby uniknąć podstawowego wyglądu dokumentu HTML.
```{r customisation, warning=FALSE, message=FALSE}
knitr::read_chunk('customisation.R')
source("customisation.R", echo = F, local = knitr::knit_global())
```
- Plik źródłowy kustomizcji motywów
```{r customisation.R, eval=FALSE}
```
# Analiza
## Metadane artystów
Na początek przetworzyłem ramkę danych `OSet_artists`, która zawierała metadane o artystach. Ujednoliciłem również niektóre największe gatunki, ponieważ same dane były bardzo rozdrobnione, co utrudniłoby analizę.
```{r artist_metadata}
# Data frame containing metadata about artists
OSet_artists <- import("clean_data/musicoset_metadata/artists.csv")
# OSet_artists genre variables unification
OSet_artists <- OSet_artists %>%
mutate(main_genre = case_when(
grepl("rap", main_genre) ~ "rap",
grepl("hip hop", main_genre) ~ "rap",
grepl("drill", main_genre) ~ "rap",
grepl("rock", main_genre) ~ "rock",
grepl("country", main_genre) ~ "country",
grepl("r&b", main_genre) ~ "r&b",
grepl("edm", main_genre) ~ "edm",
grepl("pop", main_genre) ~ "pop",
grepl("soul", main_genre) ~ "soul",
.default = as.character(main_genre)
))
OSet_artists_genre <- OSet_artists %>%
select(c("name", "main_genre"))
flextable(head(OSet_artists_genre)) %>% theme_design()
```
## Przetwarzanie danych
Przygotowanie ramek zawierających informacje o ilości streamów piosenek.
```{r, warning=FALSE}
# Top songs df cleaning
ww_totals <- ww_totals %>%
mutate(across(c('Total', 'Today'), ~ str_replace(., ",", ""))) %>%
mutate(across(c('Total', 'Today'), ~ str_replace(., ",", ""))) %>%
mutate(
Total = as.numeric(Total),
Today = as.numeric(Today)
) %>%
select(`Artist and Title`, Total) %>%
arrange(desc(Total))
apple_songs_totals <- apple_songs_totals %>%
mutate(across(c('Total', 'Today'), ~ str_replace(., ",", ""))) %>%
mutate(across(c('Total', 'Today'), ~ str_replace(., ",", ""))) %>%
mutate(
Total = as.numeric(Total),
Today = as.numeric(Today)
) %>%
select(`Artist and Title`, Total) %>%
arrange(desc(Total))
spotify_most_streamed_songs <- spotify_most_streamed_songs %>%
mutate_all(~ gsub('"', '', .)) %>%
rename(Total = 'Streams(billions)') %>%
mutate(Total = as.numeric(Total) * 1000000000) %>%
drop_na() %>% # dropping rows that were not matched
mutate('Artist and Title' = paste(`Artist(s)`, Song, sep = " - ")) %>%
select(`Artist and Title`, Total) %>%
arrange(desc(Total))
# Vector of substrings to remove
substrings_to_remove <- c("Official.*", "M/V", "MV", "Video")
# Create a regex pattern from the vector of substrings
pattern <- str_c(substrings_to_remove, collapse = "|")
youtube_topvideos <- youtube_topvideos %>%
mutate(across(c("Views", "Yesterday"), ~ gsub('\\,', '', .))) %>%
mutate(across(c('Views', 'Yesterday'), ~ str_replace(., ",", ""))) %>%
mutate(across(c('Views'), ~ str_replace(., ',', ""))) %>%
mutate(
Views = as.numeric(Views),
Yesterday = as.numeric(Yesterday)
) %>%
rename('Artist and Title' = Video) %>%
rename(Total = Views) %>%
mutate(`Artist and Title` = str_replace(`Artist and Title`, "\\(.*\\)", "")) %>%
mutate(`Artist and Title` = str_replace(`Artist and Title`, "\\[.*\\]", "")) %>%
mutate(`Artist and Title` = str_remove_all(`Artist and Title`, pattern)) %>%
select(`Artist and Title`, Total) %>%
arrange(desc(Total))
```
## Wszyskie platformy
### Przetwarzanie danych
Za pomocą nowo utworzonej ramki `OSet_artists_genre` z gatunkami i imionami artystów połączyłem ramki z [kworb.net](https://kworb.net/) zawierające informacje o tym ile byli słuchani, aby mieć pogląd na to jakie są najczęściej słuchane gatunki na wszystkich platformach.
Należyte było przekonwertowanie niektórych kolumn, ponieważ wszystkie na początku były typu `character`.
Dla pozostałych platform użyłem podobnych metod.
```{r preferable_genres}
colnames(OSet_artists_genre) <- c("Artist", "Genre")
artists_genre_comparison <- ww_artisttotals%>%
inner_join(
spotify_listeners,
by = "Artist",
suffix = c(".ww", ".spotify")
) %>%
inner_join(
youtube_archive,
by = "Artist",
suffix = c(".ww", ".youtube")
) %>%
inner_join(
apple_songs_artisttotals,
by = "Artist",
suffix = c(".ww", ".apple")
) %>%
inner_join(
OSet_artists_genre,
by = "Artist",
suffix = c(".ww", ".genre")
)
# Column cleaning
artists_genre_comparison$Total.youtube <- str_replace_all(artists_genre_comparison$Total.youtube, ",","")
artists_genre_comparison$Total.ww <- str_replace_all(artists_genre_comparison$Total.ww, ",", "")
artists_genre_comparison$PkListeners <- str_replace_all(artists_genre_comparison$PkListeners, ",", "")
artists_genre_comparison$Total <- str_replace_all(artists_genre_comparison$Total, ",", "")
artists_genre_comparison$Listeners <- str_replace_all(artists_genre_comparison$Listeners , ",", "")
artists_genre_comparison <- artists_genre_comparison %>%
transform(
Total.youtube = as.numeric(Total.youtube),
Total.ww = as.numeric(Total.ww),
PkListeners = as.numeric(PkListeners),
Total = as.numeric(Total),
Listeners = as.numeric(Listeners)
) %>%
mutate(
# Total.youtube column is equal to total views in millions
Total.youtube = as.numeric(Total.youtube) * 1000000
) %>%
rename(Total.apple = Total, Total.spotify = PkListeners)
# Sum of all the listeners and views across all of the dsp column
artists_genre_comparison <- artists_genre_comparison %>%
mutate(
Sum_listeners_views_across = Total.youtube + Total.ww + Total.apple + Total.spotify
) %>%
arrange(desc(Sum_listeners_views_across))
```
### Najczęściej słuchane gatunki
```{r}
preferable_genres <- artists_genre_comparison %>%
select(Artist, Genre, Sum_listeners_views_across) %>%
group_by(Genre) %>%
count() %>%
arrange(desc(n))
preferable_genres_flex <- flextable(preferable_genres) %>% theme_design()
flextable(head(preferable_genres)) %>% theme_design()
```
### Wizualizacja - gatunki
```{r}
bar_plot(preferable_genres, "#edc491", "Najczęciej słuchane gatunki", "plot_top_genres")
plot_top_genres
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_genres.png', plot = plot_top_genres, path = 'plots/')
```
### Najczęściej słuchani artyści
```{r}
preferable_artists <- artists_genre_comparison %>%
select(Artist, Sum_listeners_views_across) %>%
arrange(desc(Sum_listeners_views_across))
flextable(top_n(preferable_artists, 10)) %>% theme_design()
```
### Wizualizacja - artyści
```{r}
bubble_plots(artists_genre_comparison, Sum_listeners_views_across, "#edc491", "Najczęściej streamowani artyści", "plot_top_artists")
plot_top_artists
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_artists.png', plot = plot_top_artists, path = 'plots/')
```
Wersja interaktywna:
```{r}
plot_top_artists_interactive
```
## Spotify
### Przetwarzanie danych
```{r}
preferable_genres_spotify <- suppressWarnings({
spotify_artists %>%
mutate(across(c('Streams', 'Daily', 'As lead', 'Solo', 'As feature'), ~ str_replace(., ",", ""))) %>%
mutate(across(c('Streams', 'Daily', 'As lead', 'Solo', 'As feature'), ~ as.numeric(.) * 1000000)) %>%
left_join(
OSet_artists_genre,
by = "Artist",
suffix = c(".spotify", ".oset")
) %>%
drop_na() %>% # Dropping rows that were not matched in left_join
select(
Artist, Genre, Streams
) %>%
group_by(Genre) %>%
count() %>%
arrange(desc(n))
})
```
### Najczęściej słuchane gatunki
```{r}
preferable_genres_spotify_flex <- flextable(preferable_genres_spotify) %>% add_header_lines("Spotify") %>% theme_design()
flextable(head(preferable_genres_spotify)) %>% add_header_lines("Spotify") %>% theme_design()
```
### Wizualizacja - gatunki
```{r}
bar_plot(preferable_genres_spotify, "#6cd980", "Najczęściej słuchane gatunki na Spotify", "plot_top_genres_spotify")
plot_top_genres_spotify
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_genres_spotify.png', plot = plot_top_genres_spotify, path = 'plots/')
```
### Najczęściej słuchani artyści
```{r}
preferable_artists_spotify <- artists_genre_comparison %>%
select(Artist, Total.spotify) %>%
arrange(desc(Total.spotify))
flextable(top_n(preferable_artists_spotify, 10)) %>% theme_design()
```
### Wizualizacja - artyści
```{r}
bubble_plots(artists_genre_comparison, Total.spotify, "#6cd980", "Najczęściej streamowani artyści na Spotify", "plot_top_artists_spotify")
plot_top_artists_spotify
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_artists_spotify.png', plot = plot_top_artists_spotify, path = 'plots/')
```
Wersja interaktywna:
```{r}
plot_top_artists_spotify_interactive
```
### Najczęściej słuchane piosenki
```{r}
spotify_most_streamed_songs_flex <- flextable(spotify_most_streamed_songs) %>% add_header_lines("Spotify") %>% theme_design()
spotify_most_streamed_songs_scrollable_flex <- htmltools::tags$div(
style = "overflow-x: auto; overflow-y: auto; height: 400px; width: 100%;",
flextable::htmltools_value(spotify_most_streamed_songs_flex)
)
htmltools::HTML(as.character(spotify_most_streamed_songs_scrollable_flex))
```
## Apple Music
### Przetwarzanie danych
```{r}
preferable_genres_apple <- suppressWarnings({
apple_songs_artisttotals %>%
mutate(across(c('Total', 'Today'), ~ str_replace(., ",", ""))) %>%
mutate(across(c('Total', 'Today'), ~ as.numeric(.) * 1000000)) %>%
left_join(
OSet_artists_genre,
by = "Artist",
suffix = c(".apple", ".oset")
) %>%
drop_na() %>% # dropping rows that were not matched in left_join
select(
Artist, Genre, Total
) %>%
group_by(Genre) %>%
count() %>%
arrange(desc(n))
})
preferable_genres_apple <- preferable_genres_apple[-6,] # removing empty row
```
### Najczęściej słuchane gatunki
```{r}
preferable_genres_apple_flex <- flextable(preferable_genres_apple) %>% add_header_lines("Apple Music") %>% theme_design()
flextable(head(preferable_genres_apple)) %>% add_header_lines("Apple Music") %>% theme_design()
```
### Wizualizacja - gatunki
```{r}
bar_plot(preferable_genres_apple, "#fa2a44", "Najczęściej słuchane gatunki na Apple Music", "plot_top_genres_apple")
plot_top_genres_apple
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_genres_apple.png', plot = plot_top_genres_apple, path = 'plots/')
```
### Najczęściej słuchani artyści
```{r}
preferable_artists_apple <- artists_genre_comparison %>%
select(Artist, Total.apple) %>%
arrange(desc(Total.apple))
flextable(top_n(preferable_artists_apple, 10)) %>% theme_design()
```
### Wizualizacja - artyści
```{r}
bubble_plots(artists_genre_comparison, Total.apple, "#e04a5d", "Najczęściej streamowani artyści na Apple Music", "plot_top_artists_apple")
plot_top_artists_apple
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_artists_apple.png', plot = plot_top_artists_apple, path = 'plots/')
```
Wersja interaktywna:
```{r}
plot_top_artists_apple_interactive
```
### Najczęściej słuchane piosenki
```{r}
apple_songs_totals_flex <- flextable(apple_songs_totals) %>% add_header_lines("Apple Music") %>% theme_design()
apple_songs_totals_scrollable_flex <- htmltools::tags$div(
style = "overflow-x: auto; overflow-y: auto; height: 400px; width: 100%;",
flextable::htmltools_value(apple_songs_totals_flex)
)
htmltools::HTML(as.character(apple_songs_totals_scrollable_flex))
```
## YouTube
### Przetwarzanie danych
```{r}
preferable_genres_yt <- suppressWarnings({
youtube_archive %>%
mutate(across(c('Total', '100M'), ~ str_replace(., ",", ""))) %>%
mutate(across(c('Total', '100M'), ~ as.numeric(.) * 1000000)) %>%
left_join(
OSet_artists_genre,
by = "Artist",
suffix = c(".youtube", ".oset")
) %>%
drop_na() %>% # Dropping rows that were not matched in left_join
select(
Artist, Genre, Total
) %>%
group_by(Genre) %>%
count() %>%
arrange(desc(n))
})
```
### Najczęściej słuchane gatunki
```{r}
preferable_genres_yt_flex <- flextable(preferable_genres_yt) %>% add_header_lines("YouTube") %>% theme_design()
flextable(head(preferable_genres_yt)) %>% add_header_lines("YouTube") %>% theme_design()
```
### Wizualizacja - gatunki
```{r}
bar_plot(preferable_genres_yt, "#db0000", "Najczęściej słuchane gatunki na YouTube", "plot_top_genres_yt")
plot_top_genres_yt
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_genres_yt.png', plot = plot_top_genres_yt, path = 'plots/')
```
### Najczęściej słuchani artyści
```{r}
preferable_artists_youtube <- artists_genre_comparison %>%
select(Artist, Total.youtube) %>%
arrange(desc(Total.youtube))
flextable(top_n(preferable_artists_youtube, 10)) %>% theme_design()
```
### Wizualizacja - artyści
```{r}
bubble_plots(artists_genre_comparison, Total.youtube, "#deb3b1", "Najczęściej streamowani artyści na YouTube", "plot_top_artists_yt")
plot_top_artists_yt
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_artists_yt.png', plot = plot_top_artists_yt, path = 'plots/')
```
Wersja interaktywna:
```{r}
plot_top_artists_yt_interactive
```
### Najczęściej słuchane piosenki
```{r}
youtube_topvideos_flex <- flextable(youtube_topvideos) %>% add_header_lines("YouTube") %>% theme_design()
youtube_topvideos_scrollable_flex <- htmltools::tags$div(
style = "overflow-x: auto; overflow-y: auto; height: 400px; width: 100%;",
flextable::htmltools_value(youtube_topvideos_flex)
)
htmltools::HTML(as.character(youtube_topvideos_scrollable_flex))
```
## iTunes
### Przetwarzanie danych
```{r}
preferable_genres_itunes <- suppressWarnings({
ww_artisttotals %>%
mutate(across(c('Total', 'Today'), ~ str_replace(., ",", ""))) %>%
mutate(across(c('Total', 'Today'), ~ as.numeric(.) * 1000000)) %>%
left_join(
OSet_artists_genre,
by = "Artist",
suffix = c(".ww", ".oset")
) %>%
drop_na() %>% # dropping rows that were not matched in left_join
select(
Artist, Genre, Total
) %>%
group_by(Genre) %>%
count() %>%
arrange(desc(n))
})
```
### Najczęściej słuchane gatunki
```{r}
preferable_genres_itunes <- preferable_genres_itunes[-5,] # removing empty genre row
preferable_genres_itunes_flex <- flextable(preferable_genres_itunes) %>% add_header_lines("iTunes") %>% theme_design()
flextable(head(preferable_genres_itunes)) %>% add_header_lines("iTunes") %>% theme_design()
```
### Wizualizacja - gatunki
```{r}
bar_plot(preferable_genres_itunes, "#649fe8", "Najczęściej słuchane gatunki na iTunes", "plot_top_genres_itunes")
plot_top_genres_itunes
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_genres_itunes.png', plot = plot_top_genres_itunes, path = 'plots/')
```
### Najczęściej słuchani artyści
```{r}
preferable_artists_itunes <- artists_genre_comparison %>%
select(Artist, Total.ww) %>%
arrange(desc(Total.ww))
flextable(top_n(preferable_artists_itunes , 10)) %>% theme_design()
```
### Wizualizacja - artyści
```{r}
bubble_plots(artists_genre_comparison, Total.ww, "#649fe8", "Najczęściej streamowani artyści na iTunes", "plot_top_artists_itunes")
plot_top_artists_itunes
```
```{r, echo=FALSE, results='hide'}
ggsave('plot_top_artists_itunes.png', plot = plot_top_artists_itunes, path = 'plots/')
```
Wersja interaktywna:
```{r}
plot_top_artists_itunes_interactive
```
### Najczęściej słuchane piosenki
```{r}
ww_totals_flex <- flextable(ww_totals) %>% add_header_lines("iTunes") %>% theme_design()
ww_totals_scrollable_flex <- htmltools::tags$div(
style = "overflow-x: auto; overflow-y: auto; height: 400px; width: 100%;",
flextable::htmltools_value(ww_totals_flex)
)
htmltools::HTML(as.character(ww_totals_scrollable_flex))
```
## Podobieństwa i różnice
Ile jest tych samych a ile różnych piosenek pomiędzy wszystkimi platformami?
### Przetwarzanie danych
```{r, warning=FALSE,message=FALSE,error=FALSE, results='hide'}
top_songs_total <- bind_rows(spotify_most_streamed_songs %>% top_n(50), ww_totals %>% top_n(50), apple_songs_totals %>% top_n(50), youtube_topvideos %>% top_n(50))
top_songs_total_scatter <- top_songs_total %>%
group_by(`Artist and Title`) %>%
mutate(is_duplicate = n() > 1) %>%
ungroup()
count_data <- top_songs_total_scatter %>%
summarise(count_true = sum(is_duplicate),
count_false = sum(!is_duplicate))
top_songs_total_bar <- data.frame(
Duplicate = c("Same", "Different"),
Count = c(count_data$count_true, count_data$count_false)
)
count_data_flex <- flextable(count_data) %>% theme_design()
```
```{r}
count_data_flex
```
Z top 50 najwięcej słuchanych piosenek ze wszystkich platform jedynie 57 pokrywa się.
```{r}
(count_data$count_true/(count_data$count_false + count_data$count_true))*100
```
Co stanowi jedynie 28,5%.
### Wizualizacja
```{r, warning=FALSE,message=FALSE,error=FALSE, results='hide'}
top_songs_differences_bar_plot <- top_songs_total_bar %>% ggplot(
aes(
x = Duplicate,
y = Count,
fill = Duplicate
)
) + geom_bar(
stat = "identity",
width = 0.5,
) + labs(
title = "Różnice w top 100 piosenek z każdego serwisu",
) + xlab(
""
) + ylab(
""
) + theme_fivethirtyeight() + scale_fill_fivethirtyeight() + theme(
plot.title = element_text(size = 13),
plot.subtitle = element_text(size = 10),
legend.position = "none"
) +
scale_fill_manual(values = c("Same" = "#d13e2e", "Different" = "#2e85d1"))
top_songs_differences_scatter_plot <- top_songs_total_scatter %>% ggplot(aes(x = `Artist and Title`, y = Total, color = is_duplicate)) +
geom_point(size = 3) +
scale_y_log10() +
labs(
title = "Różnice w top 100 piosenek z każdego serwisu"
) + xlab(
"Ilość streamów"
) + ylab(
""
) + theme_fivethirtyeight() + scale_fill_fivethirtyeight() + theme(
plot.title = element_text(size = 13),
plot.subtitle = element_text(size = 10),
legend.position = "none",
axis.text.x = element_blank(),
axis.text.y = element_blank(),
panel.grid.major = element_line(color = "grey90", linewidth = 0.5),
panel.grid.minor = element_line(color = "grey95", linewidth = 0.25)
) +
scale_color_manual(values = c("TRUE" = "#d13e2e", "FALSE" = "#2e85d1"))
top_songs_differences_bar_plot
top_songs_differences_scatter_plot
```
```{r, echo=FALSE, results='hide'}
ggsave('top_songs_differences_bar_plot.png', plot = top_songs_differences_bar_plot, path = 'plots/')
ggsave('top_songs_differences_scatter_plot.png', plot = top_songs_differences_scatter_plot, path = 'plots/')
```
# Podsumowanie
## Najczęściej słuchane gatunki
```{r}
plot_top_genres
plot_top_genres_spotify
plot_top_genres_apple
plot_top_genres_yt
plot_top_genres_itunes
```
## Najczęściej słuchani artyści
```{r}
plot_top_artists_interactive
plot_top_artists_spotify_interactive
plot_top_artists_apple_interactive
plot_top_artists_yt_interactive
plot_top_artists_itunes_interactive
```
## Najczęściej słuchane piosenki
```{r}
htmltools::HTML(as.character(spotify_most_streamed_songs_scrollable_flex))
htmltools::HTML(as.character(apple_songs_totals_scrollable_flex))
htmltools::HTML(as.character(youtube_topvideos_scrollable_flex))
htmltools::HTML(as.character(ww_totals_scrollable_flex))
```
## Wnioski
- W najczęściej słuchanych gatunkach zawsze pojawiały się: Pop, Rap oraz Rock
Nie jest zaskoczeniem, że gatunek Pop jest najbardziej popularny. W dzisiejszych czaszch tak samo Rap, który aktualnie zaczyna powoli wypierać klasyczną muzykę Pop. Dlatego powstaje coraz więcej łączenia tych dwóch gatunków.
- Gatunek Rock, który stoi na trzecim miejscu, pomimo ogólnej percepcji, że ten gatunek powoli umiera
- Gatunek Latin, który pnie się coraz wyżej, wywierając wpływ na inne gatunki
- Gatunki na platformach Spotify oraz Apple Music były w miarę do siebie zbliżone, na iTunes country wyprzedziło rap, na YouTube pojawił się alternative metal
- Spotify oraz Apple Music były w miarę zbliżone do siebie pod względem topowych artystów, lecz na różnych pozycjach
- iTunes oraz YouTube są zdominowane przez artystów z większymi hitami, po których dopiero pojawiają się artyści widziani z pozostałych platform
- Najczęściej słuchane piosenki na iTunes to w większości piosenki z największą popularnością około 10 lat temu
- Najczęściej słuchane piosenki na YouTube zawierają najwięcej artystów jednego przeboju
- Najwięcej słuchaczy posiada Spotify
Ilość linijek we wszystkich plikach:
```{bash, engine.opts='-l'}
count_lines_of_code() {
local directory="$1"
local exclude_directory="$2"
local total_lines=0
if [ -z "$directory" ]; then
echo "Please provide a directory."
return 1
fi
if [ -z "$exclude_directory" ]; then
echo "Please provide a directory to exclude."
return 1
fi
# Find all .R and .Rmd files in the specified directory excluding the exclude_directory and count their lines
for file in $(find "$directory" -path "$exclude_directory" -prune -o -type f \( -name "*.R" -o -name "*.Rmd" \) -print); do
local lines=$(wc -l < "$file")
total_lines=$((total_lines + lines))
done
echo "Total lines of code in .R and .Rmd files in $directory excluding $exclude_directory: $total_lines"
}
# Call the function with a specific directory and exclude directory
count_lines_of_code "." "./packrat"
```