Graph operators

Graph operators handle graphs in terms of set theory.

graph.compose(g1, g2)
graph.difference(big, small)
graph.complementer(graph, loops=FALSE)
x %c% y
x %du% y
x %m% y
x %s% y
x %u% y
Graph objects or lists of graph objects.
Graph objects.
Logical constant, whether to generate loop edges.

A graph is homogenous binary relation over the set 0, ..., |V|-1, |V| is the number of vertices in the graph. A homogenous binary relation is a set of ordered (directed graphs) or unordered (undirected graphs) pairs taken from 0, ..., |V|-1. The functions documented here handle graphs as relations.

graph.union creates the union of two or more graphs. Ie. only edges which are included in at least one graph will be part of the new graph. This function can be also used via the %u% operator.

graph.disjoint.union creates a union of two or more disjoint graphs. Thus first the vertices in the second, third, etc. graphs are relabeled to have completely disjoint graphs. Then a simple union is created. This function can also be used via the %du% operator.

graph.intersection creates the intersection of two or more graphs: only edges present in all graphs will be included. The corresponding operator is %s%.

graph.difference creates the difference of two graphs. Only edges present in the first graph but not in the second will be be included in the new graph. The corresponding operator is %m%.

graph.complementer creates the complementer of a graph. Only edges which are not present in the original graph will be included in the new graph.

graph.compose creates the composition of two graphs. The new graph will contain an (a,b) edge only if there is a vertex c, such that edge (a,c) is included in the first graph and (c,b) is included in the second graph. The corresponding operator is %c%.

graph.complementer keeps graph and vertex attriubutes, edge attributes are lost. graph.difference keeps all attributes (graph, vertex and edge) of the first graph. The other functions do not handle vertex and edge attributes, the new graph will have no attributes at all.


  • A new graph object.


Graph operators

  • graph.union
  • graph.disjoint.union
  • graph.intersection
  • graph.compose
  • graph.difference
  • graph.complementer
  • %c%
  • %du%
  • %m%
  • %s%
  • %u%
g1 <- graph.ring(10)
g2 <-, mode="undirected")
graph.union(g1, g2)
graph.disjoint.union(g1, g2)
graph.intersection(g1, g2)
graph.difference(g1, g2)
graph.compose(g1, g2)

## graph complementer keeps graph and vertex attributes
g2$layout <-
V(g2)$name <- letters[1:vcount(g2)]
cg2 <- graph.complementer(g2)

## graph difference keeps the attributes of the first graph
g1$name <- "Ring"
V(g1)$name <- LETTERS[1:vcount(g1)]
E(g1)$weight <- round(runif(ecount(g1))*10)
dg <- graph.difference(g1, g2)
print(dg, g=TRUE, v=TRUE, e=TRUE)
Documentation reproduced from package igraph, version 0.6.5-2, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.