View source: R/combine_layers.R
| combine_layers | R Documentation |
Return a merged graph from two graph layers.
combine_layers(graph1, graph2 = NULL, interaction.df = NULL)
graph1 |
an igraph object or list of igraph ( |
graph2 |
an igraph object or list of igraph ( |
interaction.df |
(optional) a 2 colomns data.frame (from, to) describing the edges between vertices from both graphs. |
If graph2 is a single graph, it will be merged to each element of
graph1 (igraph or list.igraph).
If graph2 is a list of graph (list.igraph), each element of
graph1 and each element of graph2 are merged in pairs.
Optionally, interaction.df should be provide if any vertex are shared
between graphs. It can also be used to extend the first graph.
In both scenarios, vertex attributes are kept. If a vertex attribute is missing from graph1 or graph2, NULL value is added. Otherwise, if there is an overlap between attribute values for the same vertex, attribute from graph2 is dropped.
a merged graph with both vertex attributes from graph1 and graph2.
# with single graphs
graph1 <- igraph::graph_from_data_frame(list(from = c('A', 'B'),
to = c('B', 'C')),
directed = FALSE)
graph2 <- igraph::graph_from_data_frame(list(from = c(1),
to = c(2)),
directed = FALSE)
res <- combine_layers(graph1 = graph1,
graph2 = graph2)
# with list of graphs
graph1.list <- list(graph1, graph1)
graph2.list <- list(graph2, graph2)
class(graph1.list) <- class(graph2.list) <- 'list.igraph'
res <- combine_layers(graph1 = graph1.list,
graph2 = graph2)
res <- combine_layers(graph1 = graph1.list,
graph2 = graph2.list)
# with interaction dataframe
interaction.df1 <- as.data.frame(list(from = c('C', 'B'), to = c(1, 2)))
res <- combine_layers(graph1 = graph1.list,
graph2 = graph2,
interaction.df = interaction.df1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.