-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.qmd
55 lines (45 loc) · 1.05 KB
/
index.qmd
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
---
format:
gfm:
fig-format: svg
fig-dpi: 300
# knitr:
# opts_chunk:
# fig
---
```{r}
library(netplot)
library(igraph)
library(data.table)
library(rgexf)
edgelist <- fread("edgelist.csv")
vertices <- fread("vertices.csv")
# Checking which edgelist vertex is not in the list of vertices
vnames_in_edgelist <- edgelist[,c(source, target)]
vnames_in_edgelist[
which(!vnames_in_edgelist %in% vertices[, name])
]
net <- graph_from_data_frame(edgelist, directed = FALSE, vertices = vertices)
```
```{r}
set.seed(331)
np <- nplot(
net,
vertex.color = ~type,
vertex.size.range = c(.015, .02),
edge.color = ~ego + alter,
edge.curvature = pi/6,
vertex.label.show = 1
)
V(net)$color <- get_vertex_gpar(np, "core", "col")$col
E(net)$color <- get_edge_gpar(np, "line", "col")$col[1,]
np
```
```{r}
#| eval: false
# Saving the gexf object
pos <- cbind(np$.layout, 0)
colnames(pos) <- c("x", "y", "z")
net_gexf <- igraph.to.gexf(net, nodesVizAtt = list(position = pos))
plot(net_gexf, dir = "docs", nodeSizeFactor = .3, curvedEdges = FALSE)
```