-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.Rmd
71 lines (60 loc) · 2.01 KB
/
index.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
---
title: "Metabolic Modelling Techniques"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
documentclass: book
bibliography: [refs.bib, packages.bib]
biblio-style: apalike
link-citations: yes
---
# Overview
```{r echo=FALSE}
temp <- purrr::quietly(library)(tidyverse)
temp <- purrr::quietly(library)(yaml)
temp <- purrr::quietly(library)(visNetwork)
treefun_character <- function(x){
return(list(name = x, children = list()))
}
treefun_onelist <- function(x){
list(name = names(x),
children = treefun(x[[1]]))
}
treefun <- function(x){
c(x %>% keep(is_list) %>% map(treefun_onelist),
x %>% keep(is_character) %>% map(treefun_character))
}
getNodes <- function(x){
bind_rows(tibble::as_data_frame(x[names(x)!='children']) %>%
mutate(nchildren = length(x$children)),
map_df(x$children %>% keep(is_list), getNodes)
)
}
getEdges <- function(x){
if(length(x$children)==0){return(NULL)}
bind_rows(data_frame(from = x$name, to = x$children %>% map_chr('name')),
map_df(x$children, getEdges))
}
tax <- read_file('data/taxonomy.yaml') %>%
yaml.load() %>%
treefun_onelist()
visNetwork(nodes = getNodes(tax) %>%
mutate(id=name,
title=name,
label=name,
shape = if_else(nchildren>=1, 'box', 'text')),
edges = getEdges(tax),
height = '1000px',
width = '750px') %>%
visHierarchicalLayout(direction = 'LR', sortMethod = 'directed', levelSeparation=1000) %>%
visPhysics(solver='hierarchicalRepulsion',
hierarchicalRepulsion = list(nodeDistance = 150,
springLength = 150,
springConstant= 0.01,
damping=0.5
)
) %>%
visNodes(font = list(size = 60, face = 'arial'), color = list(background = 'white')) %>%
visEdges(smooth = list(enabled=TRUE, type='continuous')) %>%
visExport(type='pdf')
```