add_edge_layer: add_edge_layer

Description Usage Arguments Examples

View source: R/explorers.R

Description

Adds additional edges to a graph, with a binary variable to identify the new edges. Returns a graph object with edge attribute 'add' which is TRUE or FALSE. The idea is that a first edge list generates the structure for the nodes, and then a second edge list is plotted alongside these original edges. All the nodes should be specified in a single node list

Usage

1
add_edge_layer(graph, edges_add)

Arguments

graph

a tidygraph object

edges_add

a df of the edges to be added to the network. Should not add additional nodes and have the same edge attributes.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(1)
nds <- data.frame(id = 1:6)
egs1 <- data.frame(from = 1:6, to = sample(1:6, 6, replace = TRUE))
egs2 <- data.frame(from = 1:4, to = sample(1:6, 4, replace = TRUE))

# plotting base network
base_graph <- tbl_graph(nodes = nds, edges = egs1)
lyt <- create_layout(base_graph, layout = 'nicely')
ggraph(base_graph, layout = 'manual', node.positions = lyt) +
  geom_node_point() +
  geom_edge_link() +
  theme_graph()

# plotting extra layer
new_graph <- add_edge_layer(base_graph, egs2)
ggraph(new_graph, layout = 'manual', node.positions = lyt) +
  geom_node_point(aes(x = lyt$x, y = lyt$y)) +
  geom_edge_link(aes(edge_linetype = add)) +
  theme_graph()

benwhicks/lakit documentation built on Sept. 28, 2019, 4:27 p.m.