-
Notifications
You must be signed in to change notification settings - Fork 1
/
_common.R
54 lines (50 loc) · 1.78 KB
/
_common.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
52
53
54
set.seed(1014)
knitr::opts_chunk$set(
comment = "",
collapse = TRUE,
cache = TRUE,
echo = FALSE,
fig.align = 'center',
fig.width = 6,
fig.asp = 0.618, # 1 / phi
fig.show = "asis",
# fig.keep = "all",
message = FALSE,
out.width = "100%", #"70%"
warning = FALSE
)
options(dplyr.print_min = 6, dplyr.print_max = 6)
# Supress crayon output
options(crayon.enabled = FALSE)
library(igraph)
my_igraph <- function(g, .layout = "layout_with_kk", .vertex.size = 30, ...) {
stopifnot("Must be igraph" = igraph::is.igraph(g))
stopifnot("Must be character" = is.character(.layout))
igraph::plot.igraph(g,
# Feel:
layout = eval(as.name(.layout)),
# Vertex:
vertex.color = "lightblue",
vertex.size = .vertex.size,
# Edges:
edges.color = "grey",
# Catch all
...
)
}
my_bigraph <- function(g, .layout = "layout_as_bipartite", ...) {
stopifnot("Must be igraph" = igraph::is.igraph(g))
stopifnot("Must be character" = is.character(.layout))
igraph::plot.igraph(g,
# Feel:
layout = eval(as.name(.layout)),
# Vertex:
vertex.color = ifelse(igraph::get.vertex.attribute(g, name = "type"), "red", "lightblue"),
vertex.shape = ifelse(igraph::get.vertex.attribute(g, name = "type"), "square", "circle"),
vertex.size = ifelse(igraph::get.vertex.attribute(g, name = "type"), 40, 30),
# Edges:
edges.color = "grey",
# Catch all
...
)
}