[73f552]: / man / combine_layers.Rd

Download this file

68 lines (57 with data), 2.4 kB

 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
62
63
64
65
66
67
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/combine_layers.R
\name{combine_layers}
\alias{combine_layers}
\title{Combine layers}
\usage{
combine_layers(graph1, graph2 = NULL, interaction.df = NULL)
}
\arguments{
\item{graph1}{an igraph object or list of igraph (\code{list.igraph}).}
\item{graph2}{an igraph object or list of igraph (\code{list.igraph}) with
the same length as \code{graph1}.}
\item{interaction.df}{(optional) a 2 colomns data.frame (from, to)
describing the edges between vertices from both graphs.}
}
\value{
a merged graph with both vertex attributes from graph1 and graph2.
}
\description{
Return a merged graph from two graph layers.
}
\details{
If \code{graph2} is a single graph, it will be merged to each element of
\code{graph1} (\code{igraph} or \code{list.igraph}).
If \code{graph2} is a list of graph (\code{list.igraph}), each element of
\code{graph1} and each element of \code{graph2} are merged in pairs.
Optionally, \code{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.
}
\examples{
# 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)
}