-
Notifications
You must be signed in to change notification settings - Fork 0
/
getData.r
51 lines (40 loc) · 1.62 KB
/
getData.r
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
# Get data and format as graph
# Nathan Pratt
# 2020-01-01
ingredientsUrl = "https://elderscrolls.fandom.com/wiki/Ingredients_(Skyrim)"
# get ingredient table
page = html(ingredientsUrl)
tables = page %>%
html_nodes("table")
ingredientTable = html_table(tables[[1]])
# clean up symbols from names (except "'" and space)
ingredientTable$Ingredient = str_replace_all(ingredientTable$Ingredient, "[^a-zA-Z'\\s]", "")
#### Convert to graph format ####
# Nodes
# Ingredients
ingredientNodes = ingredientTable %>%
select(Ingredient, Obtained) %>%
mutate(Type = "Ingredient", Name = Ingredient, Comments = Obtained, Count = 0) %>%
select(Name, Type, Count, Comments)
# effects
effectNodes = data.frame(Name = unique(c(ingredientTable$`Primary Effect`, ingredientTable$`Secondary Effect`,
ingredientTable$`Tertiary Effect`, ingredientTable$`Quaternary Effect`)),
Type = "Effect")
alchemyNodes = bind_rows(ingredientNodes, effectNodes)
# set colors
cols = c("lightsteelblue3", "tomato")
alchemyNodes$Type = factor(alchemyNodes$Type)
alchemyNodes$color = cols[alchemyNodes$Type]
# edges
alchemyEdges = ingredientTable %>%
mutate(id1 = Ingredient) %>%
select(id1, `Primary Effect`, `Secondary Effect`, `Tertiary Effect`, `Quaternary Effect`) %>%
gather(key = effectNumber_remove, value = id2, -id1) %>%
mutate(Known = F) %>%
select(id1, id2, Known)
# create graph
alchemyGraph = graph.data.frame(alchemyEdges, directed = F, vertices = alchemyNodes)
# remove values that will no longer be used
rm(ingredientsUrl, page, tables)
# save graph
saveRDS(alchemyGraph, file.choose())