This repository was archived by the owner on Feb 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic.R
More file actions
55 lines (48 loc) · 1.44 KB
/
static.R
File metadata and controls
55 lines (48 loc) · 1.44 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
45
46
47
48
49
50
51
52
53
54
55
library(geniusr)
library(rvest)
library(xml2)
library(tidyverse)
library(igraph)
library(ggraph)
source("./get_lyrics.R")
get_lyric_data <- function(artistname, songname) {
lyric_data <- tibble(NULL)
while (nrow(lyric_data) == 0) {
lyric_data <- get_lyrics_search(artistname, songname)
Sys.sleep(4)
}
lyric_data %>%
select(line) %>%
drop_na() %>%
rename(LyricA = line) %>%
mutate(LyricB = lead(LyricA)) %>%
drop_na() %>%
count(LyricA, LyricB, sort=TRUE) %>%
filter(n > 1) %>%
graph_from_data_frame()
}
create_graph <- function(lyric_data, artistname, songname) {
a <- grid::arrow(type="closed", length=unit(3, "mm"))
set.seed(101)
ggraph(lyric_data, layout="nicely") +
geom_edge_fan(
aes(colour=factor(n)),
arrow=a,
start_cap=circle(5, "mm"),
end_cap=circle(3, "mm")
) +
geom_edge_loop(
aes(colour=factor(n), span=-30),
arrow=a,
position=position_nudge(x=0.1),
start_cap=circle(5, "mm"),
end_cap=circle(2, "mm")
) +
geom_node_text(aes(label=str_wrap(name, width=40)), hjust="inward", repel=TRUE) +
theme_void() +
scale_edge_colour_discrete(name="Co-occurrences", breaks=unique(edge_attr(lyric_data)$n)) +
theme(legend.position="bottom", plot.title=element_text(face="bold")) +
labs(title=paste(songname, "by", artistname))
}
song <- get_lyric_data("Dua Lipa", "Levitating")
create_graph(song, "Dua Lipa", "Levitating")