forked from Bioconductor/BiocStickers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypeR.R
61 lines (54 loc) · 1.66 KB
/
hypeR.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
55
56
57
58
59
60
61
require(ggplot2)
require(hexSticker)
library(network)
library(igraph)
library(sna)
library(ggnetwork)
# Option 1
set.seed(1)
ig <- igraph::sample_pa(7, power=2, directed=FALSE)
mat <- as.matrix(igraph::as_adjacency_matrix(ig))
n <- network(mat, directed=FALSE, multiple=FALSE)
n %v% "size" <- sna::degree(n)
n %v% "type" <- c("internal", "leaf")[as.numeric(degree(n) == 2)+1]
set.seed(1)
p <- ggplot(n, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(color = "grey50", alpha = 0.5) +
geom_nodes(aes(x, y, alpha=type, size = 2*size), color="gold") +
geom_nodes(aes(x, y, color=type, size = 1.5*size)) +
scale_alpha_manual(values=c("leaf"=0.5, "internal"=0)) +
scale_color_manual(values=c("leaf"="red1", "internal"="darkorchid4")) +
guides(size = FALSE) +
theme_void() +
theme(legend.position = "none")
# Option 2
set.seed(1)
ig <- igraph::sample_pa(40, power=1.6, directed=FALSE)
mat <- as.matrix(igraph::as_adjacency_matrix(ig))
n <- network(mat, directed=FALSE, multiple=FALSE)
n %v% "size" <- degree(n)
set.seed(6)
p <- ggplot(n, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(color = "#dae1e7", alpha = 0.5) +
geom_nodes(aes(x, y, size = 1.4*size), color = "#dae1e7") +
guides(size = FALSE) +
theme_void() +
theme(legend.position = "none")
set.seed(1)
sticker(subplot=p,
package='hypeR',
p_family="mono",
p_y=1.5,
p_size=8,
s_x=1.0,
s_y=.78,
s_width=1.4,
s_height=1,
l_x=1,
l_y=1,
l_width=4,
l_height=4,
l_alpha=0.2,
spotlight=TRUE,
h_fill="#162447",
h_color="#1b1b2f")