Description Usage Arguments Examples
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
1 | add_edge_layer(graph, edges_add)
|
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. |
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.