-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenre_format_data.R
More file actions
45 lines (32 loc) · 1.75 KB
/
Copy pathgenre_format_data.R
File metadata and controls
45 lines (32 loc) · 1.75 KB
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
library(dplyr)
library(ggplot2)
library(RPostgreSQL)
library(stringr)
require(DBI)
drv <- dbDriver("PostgreSQL")
db <- dbConnect(drv, user=user, host=host,
password=pw, dbname='music_analysis') #DB DATA GOES HERE
formats <- dbGetQuery(db, "SELECT * FROM releases;")
all_albums <- dbGetQuery(db, "SELECT * FROM albums;")
formats_joined <- inner_join(formats, all_albums, by = 'id')
count_format_per_year <- formats_joined %>% select(format, year) %>%
group_by(format, year) %>% summarize(total = n())
## We need to remove some outliers, like CDs prior to their inventin in 1982
count_format_per_year <- count_format_per_year %>%
filter(format != 'CD' | year > 1981)
## multiply the current year by 3 to extrapolate out
count_format_per_year <- count_format_per_year %>%
mutate(total = ifelse(year == 2019, total * 4, total))
ggplot(count_format_per_year, aes(x = year, y=total, color=format)) + geom_line()
genres <- all_albums %>% filter(genre != 'None')
count_genre_per_year <- genres %>% select(genre, year) %>%
group_by(genre, year) %>% summarize(total = n())
count_genre_per_year <- count_genre_per_year %>%
mutate(total = ifelse(year == 2019, total * 4, total)) %>% filter(year > 1955)
ggplot(count_genre_per_year, aes(x = year, y=total, color=genre)) + geom_line()
count_genre_no_rock <- count_genre_per_year %>% filter(genre != 'Rock' & year > 1960)
ggplot(count_genre_no_rock, aes(x = year, y=total, color=genre)) + geom_line()
count_genre_just_big_ones <- count_genre_no_rock %>%
filter (genre != 'Non-Music' & genre != 'Children\'s' & genre != 'Classical' &
genre != 'Stage & Screen' & genre != 'Reggae' & genre != 'Blues' & year != 2019)
ggplot(count_genre_just_big_ones, aes(x = year, y=total, color=genre)) + geom_line()