igraph – a package for network analysis
TRANSCRIPT
![Page 1: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/1.jpg)
igraph – a package for network analysis
Gabor [email protected]
Department of Medical Genetics,
University of Lausanne, Lausanne, Switzerland
![Page 2: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/2.jpg)
Outline
1. Why another graph package?
2. igraph architecture, data model and data representation
3. Manipulating graphs
4. Features and their time complexity
igraph – a package for network analysis 2
![Page 3: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/3.jpg)
Why another graph package?
• graph is slow. RBGL is slow, too.
?
1 > ba2 # graph & RBGL
2 A graphNEL graph with undirected edges
3 Number of Nodes = 100000
4 Number of Edges = 199801
![Page 4: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/4.jpg)
Why another graph package?
• graph is slow. RBGL is slow, too.
?
1 > ba2 # graph & RBGL
2 A graphNEL graph with undirected edges
3 Number of Nodes = 100000
4 Number of Edges = 199801
5 > system.time(RBGL::transitivity(ba2))
6 user system elapsed
7 7.517 0.000 7.567
![Page 5: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/5.jpg)
Why another graph package?
• graph is slow. RBGL is slow, too.
?
1 > ba2 # graph & RBGL
2 A graphNEL graph with undirected edges
3 Number of Nodes = 100000
4 Number of Edges = 199801
5 > system.time(RBGL::transitivity(ba2))
6 user system elapsed
7 7.517 0.000 7.567
8 > summary(ba) # igraph
9 Vertices: 1e+05
10 Edges: 199801
11 Directed: FALSE
12 No graph attributes.
13 No vertex attributes.
14 No edge attributes.
![Page 6: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/6.jpg)
Why another graph package?
• graph is slow. RBGL is slow, too.
?
1 > ba2 # graph & RBGL
2 A graphNEL graph with undirected edges
3 Number of Nodes = 100000
4 Number of Edges = 199801
5 > system.time(RBGL::transitivity(ba2))
6 user system elapsed
7 7.517 0.000 7.567
8 > summary(ba) # igraph
9 Vertices: 1e+05
10 Edges: 199801
11 Directed: FALSE
12 No graph attributes.
13 No vertex attributes.
14 No edge attributes.
15 > system.time(igraph::transitivity(ba))
16 user system elapsed
17 0.328 0.000 0.335
igraph – a package for network analysis 3
![Page 7: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/7.jpg)
Why another graph package?
• sna is slow. network is slow, too.
1 > net2 # SNA & network
2 Network attributes:
3 vertices = 1e+05
4 directed = TRUE
5 hyper = FALSE
6 loops = FALSE
7 multiple = FALSE
8 bipartite = FALSE
9 total edges= 199801
10 missing edges= 0
11 non-missing edges= 199801
12 ...
![Page 8: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/8.jpg)
Why another graph package?
• sna is slow. network is slow, too.
1 > net2 # SNA & network
2 Network attributes:
3 vertices = 1e+05
4 directed = TRUE
5 hyper = FALSE
6 loops = FALSE
7 multiple = FALSE
8 bipartite = FALSE
9 total edges= 199801
10 missing edges= 0
11 non-missing edges= 199801
12 ...
13 > gtrans(net2)
14 Error in matrix(0, nr = network.size(x), nc = network.size(x)) :
15 too many elements specified
igraph – a package for network analysis 4
![Page 9: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/9.jpg)
Why another graph package?
• graph is slow. RBGL is slow, too.
• sna is slow. network is slow, too.
• A generic solution was needed, i.e. a common C layer, that can be interfaced fromC/C++, R, Python, etc.
![Page 10: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/10.jpg)
Why another graph package?
• graph is slow. RBGL is slow, too.
• sna is slow. network is slow, too.
• A generic solution was needed, i.e. a common C layer, that can be interfaced fromC/C++, R, Python, etc.
graph library core
GNU R Python Ruby
igraph – a package for network analysis 5
![Page 11: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/11.jpg)
The igraph architecture
APIigraph_t
API
utility types
igraph library
R glue layerR functions
converter
igraph – a package for network analysis 6
![Page 12: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/12.jpg)
Dependencies
• Standard C/C++ libraries.
![Page 13: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/13.jpg)
Dependencies
• Standard C/C++ libraries.
• stats package, this is part of base.
![Page 14: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/14.jpg)
Dependencies
• Standard C/C++ libraries.
• stats package, this is part of base.
• Optional: libxml2 library, for readingGraphML files (included in Windows builds).
![Page 15: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/15.jpg)
Dependencies
• Standard C/C++ libraries.
• stats package, this is part of base.
• Optional: libxml2 library, for readingGraphML files (included in Windows builds).
• Optional: GMP library, graph automorphisms(not included in Windows builds).
![Page 16: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/16.jpg)
Dependencies
• Standard C/C++ libraries.
• stats package, this is part of base.
• Optional: libxml2 library, for readingGraphML files (included in Windows builds).
• Optional: GMP library, graph automorphisms(not included in Windows builds).
• Suggested packages: stats4, rgl, tcltk, RSQLite,digest, graph, Matrix.
igraph – a package for network analysis 7
![Page 17: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/17.jpg)
The igraph data model, what cannot be represented
“Mixed” graphs, with undirected and directed edges.You can “emulate” them via graph attributes.
![Page 18: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/18.jpg)
The igraph data model, what cannot be represented
“Mixed” graphs, with undirected and directed edges.You can “emulate” them via graph attributes.
Hypergraphs. Perhaps see the hypergraph package.
![Page 19: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/19.jpg)
The igraph data model, what cannot be represented
“Mixed” graphs, with undirected and directed edges.You can “emulate” them via graph attributes.
Hypergraphs. Perhaps see the hypergraph package.
No direct support for bipartite (two-mode) graphs.It is possible to handle them via graph attributes.
igraph – a package for network analysis 8
![Page 20: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/20.jpg)
Graph representation, sparse graphs
Flat data structures, indexed edge lists. Easy to handle, good for many kind of questions.
igraph – a package for network analysis 9
![Page 21: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/21.jpg)
Graph representation, sparse graphs
Flat data structures, indexed edge lists. Easy to handle, good for many kind of questions.
igraph – a package for network analysis 10
![Page 22: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/22.jpg)
Graph representation, sparse graphs
Flat data structures, indexed edge lists. Easy to handle, good for many kind of questions.
igraph – a package for network analysis 11
![Page 23: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/23.jpg)
Graph representation, sparse graphs
Flat data structures, indexed edge lists. Easy to handle, good for many kind of questions.
igraph – a package for network analysis 12
![Page 24: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/24.jpg)
Graph representation, sparse graphs
Flat data structures, indexed edge lists. Easy to handle, good for many kind of questions.
X
A
B
C
D
E
F
G
H
I
J
igraph – a package for network analysis 13
![Page 25: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/25.jpg)
Graph representation, sparse graphs
Flat data structures, indexed edge lists. Easy to handle, good for many kind of questions.
X
A
B
C
D
E
F
G
H
I
J
X
A
B
C
D
E
F
G
H
I
J
igraph – a package for network analysis 14
![Page 26: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/26.jpg)
Creating graphs, via vertex ids
1 > g <- graph( c(0,1, 1,2, 2,3, 3,4), n=6, directed=TRUE )
2 > g
3 Vertices: 6
4 Edges: 4
5 Directed: TRUE
6 Edges:
7
8 [0] 0 -> 1
9 [1] 1 -> 2
10 [2] 2 -> 3
11 [3] 3 -> 4
igraph – a package for network analysis 15
![Page 27: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/27.jpg)
Creating graphs, via vertex ids
1 > el <- cbind(0:9, 9:0)
2 > g <- graph( t(el), directed=TRUE)
3 > g
4 Vertices: 10
5 Edges: 10
6 Directed: TRUE
7 Edges:
8
9 [0] 0 -> 9
10 [1] 1 -> 8
11 [2] 2 -> 7
12 [3] 3 -> 6
13 [4] 4 -> 5
14 [5] 5 -> 4
15 [6] 6 -> 3
16 [7] 7 -> 2
17 [8] 8 -> 1
18 [9] 9 -> 0
igraph – a package for network analysis 16
![Page 28: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/28.jpg)
Creating graphs, graph.formula
1 # A simple undirected graph
2 > g <- graph.formula( Alice-Bob-Cecil-Alice,
3 Daniel-Cecil-Eugene, Cecil-Gordon )
4 > g
5 Vertices: 6
6 Edges: 6
7 Directed: FALSE
8 Edges:
9
10 [0] Alice -- Bob
11 [1] Bob -- Cecil
12 [2] Alice -- Cecil
13 [3] Cecil -- Daniel
14 [4] Cecil -- Eugene
15 [5] Cecil -- Gordon
igraph – a package for network analysis 17
![Page 29: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/29.jpg)
Creating graphs, graph.formula
1 # Another undirected graph, ":" notation
2 > g2 <- graph.formula( Alice-Bob:Cecil:Daniel,
3 Cecil:Daniel-Eugene:Gordon )
4 > g2
5 Vertices: 6
6 Edges: 7
7 Directed: FALSE
8 Edges:
9
10 [0] Alice -- Bob
11 [1] Alice -- Cecil
12 [2] Alice -- Daniel
13 [3] Cecil -- Eugene
14 [4] Cecil -- Gordon
15 [5] Daniel -- Eugene
16 [6] Daniel -- Gordon
igraph – a package for network analysis 18
![Page 30: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/30.jpg)
Creating graphs, graph.formula
1 # A directed graph
2 > g3 <- graph.formula( Alice +-+ Bob --+ Cecil
3 +-- Daniel, Eugene --+ Gordon:Helen )
4 > g3
5 Vertices: 7
6 Edges: 6
7 Directed: TRUE
8 Edges:
9
10 [0] Bob -> Alice
11 [1] Alice -> Bob
12 [2] Bob -> Cecil
13 [3] Daniel -> Cecil
14 [4] Eugene -> Gordon
15 [5] Eugene -> Helen
igraph – a package for network analysis 19
![Page 31: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/31.jpg)
Creating graphs, graph.formula
1 # A graph with isolate vertices
2 > g4 <- graph.formula( Alice -- Bob -- Daniel,
3 Cecil:Gordon, Helen )
4 > g4
5 Vertices: 6
6 Edges: 2
7 Directed: FALSE
8 Edges:
9
10 [0] Alice -- Bob
11 [1] Bob -- Daniel
12 > V(g4)
13 Vertex sequence:
14 [1] "Alice" "Bob" "Daniel"
15 [4] "Cecil" "Gordon" "Helen"
igraph – a package for network analysis 20
![Page 32: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/32.jpg)
Creating graphs, graph.formula
1 # "Arrows" can be arbitrarily long
2 > g5 <- graph.formula( Alice +---------+ Bob )
3 > g5
4 Vertices: 2
5 Edges: 2
6 Directed: TRUE
7 Edges:
8
9 [0] Bob -> Alice
10 [1] Alice -> Bob
igraph – a package for network analysis 21
![Page 33: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/33.jpg)
Creating graphs, graph.famous
1 > graph.famous("Cubical")
2 Vertices: 8
3 Edges: 12
4 Directed: FALSE
5 Edges:
6
7 [0] 0 -- 1
8 [1] 1 -- 2
9 [2] 2 -- 3
10 [3] 0 -- 3
11 [4] 4 -- 5
12 [5] 5 -- 6
13 [6] 6 -- 7
14 [7] 4 -- 7
15 [8] 0 -- 4
16 [9] 1 -- 5
17 [10] 2 -- 6
18 [11] 3 -- 7
igraph – a package for network analysis 22
![Page 34: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/34.jpg)
Creating graphs, graph.data.frame
1 > traits <- read.csv("traits.csv", head=F)
2 > traits
3 V1 V2 V3
4 1 Alice Anderson 48 F
5 2 Bob Bradford 33 M
6 3 Cecil Connor 45 F
7 4 David Daugher 34 M
8 5 Esmeralda Escobar 21 F
9 6 Frank Finley 36 M
10 7 Gabi Garbo 44 F
11 8 Helen Hunt 40 F
12 9 Iris Irving 25 F
13 10 James Jones 47 M
14 > colnames(traits) <- c("name", "age", "gender")
15 > traits[,1] <- sapply(strsplit(as.character(traits[,1]), " "), "[", 1)
igraph – a package for network analysis 23
![Page 35: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/35.jpg)
Creating graphs, graph.data.frame
1 > relations <- read.csv("relations.csv", head=F)
2 > relations
3 V1 V2 V3 V4 V5
4 1 Bob Alice N 4 4
5 2 Cecil Bob N 5 5
6 3 Cecil Alice Y 5 5
7 4 David Alice N 3 4
8 5 David Bob N 4 2
9 6 Esmeralda Alice Y 4 3
10 7 Frank Alice N 3 2
11 8 Frank Esmeralda N 4 4
12 9 Gabi Bob Y 5 5
13 10 Gabi Alice N 3 0
14 11 Helen Alice N 4 1
15 12 Iris Cecil N 0 1
16 ...
17 > colnames(relations) <- c("from", "to", "same.room",
18 "friendship", "advice")
igraph – a package for network analysis 24
![Page 36: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/36.jpg)
Creating graphs, graph.data.frame
1 > orgnet <- graph.data.frame(relations, vertices=traits)
2 > summary(orgnet)
3 Vertices: 10
4 Edges: 34
5 Directed: TRUE
6 No graph attributes.
7 Vertex attributes: name, age, gender.
8 Edge attributes: same.room, friendship, advice.
igraph – a package for network analysis 25
![Page 37: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/37.jpg)
Creating graphs, graph.data.frame
1 > plot(orgnet, layout=layout.kamada.kawai, vertex.label=V(orgnet)$name,
2 vertex.shape="rectangle", vertex.size=20, asp=FALSE)
igraph – a package for network analysis 26
![Page 38: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/38.jpg)
Creating graphs, random graphs
1 > er <- erdos.renyi.game(100, 100, type="gnm")
2 > plot(er, vertex.size=5, vertex.label=NA, asp=FALSE, vertex.shape="square",
3 layout=layout.fruchterman.reingold, edge.color="black")
igraph – a package for network analysis 27
![Page 39: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/39.jpg)
Creating graphs, random graphs
1 > ba <- ba.game(100, power=1, m=1)
2 > plot(ba, vertex.size=3, vertex.label=NA, asp=FALSE, vertex.shape="square",
3 layout=layout.fruchterman.reingold, edge.color="black",
4 edge.arrow.size=0.5)
igraph – a package for network analysis 28
![Page 40: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/40.jpg)
Meta data: graph/vertex/edge attributes
• Assigning attributes: set/get.graph/vertex/edge.attribute.
![Page 41: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/41.jpg)
Meta data: graph/vertex/edge attributes
• Assigning attributes: set/get.graph/vertex/edge.attribute.
• V(g) and E(g).
![Page 42: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/42.jpg)
Meta data: graph/vertex/edge attributes
• Assigning attributes: set/get.graph/vertex/edge.attribute.
• V(g) and E(g).
• Easy access of attributes:
1 > g <- erdos.renyi.game(30, 2/30)
2 > V(g)$color <- sample( c("red", "black"),
3 vcount(g), rep=TRUE)
4 > V(g)$color
5 [1] "red" "black" "red" "black" "black" "black" "red" "red" "red"
6 [10] "black" "black" "black" "red" "red" "black" "red" "black" "black"
7 [19] "red" "red" "black" "black" "red" "black" "black" "red" "black"
8 [28] "black" "black" "red"
9 > E(g)$color <- "grey"
igraph – a package for network analysis 29
![Page 43: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/43.jpg)
Vertex/edge selection with attributes
1 > red <- V(g)[ color == "red" ]
2 > bl <- V(g)[ color == "black" ]
3 > E(g)[ red %--% red ]$color <- "red"
4 > E(g)[ bl %--% bl ]$color <- "black"
5 > plot(g, vertex.size=5,
6 layout=layout.fruchterman.reingold,
7 vertex.label=NA)
igraph – a package for network analysis 30
![Page 44: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/44.jpg)
Visualizing graphs
• Three functions with (almost) identical interfaces.
![Page 45: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/45.jpg)
Visualizing graphs
• Three functions with (almost) identical interfaces.
• plot Uses traditional R graphics, non-interactive, 2d. Publication quality plots in allformats R supports.
1 > g <- barabasi.game(100, m=1)
2 > igraph.par("plot.layout",
3 layout.fruchterman.reingold)
4 > plot(g, vertex.size=4, vertex.label=NA,
5 edge.arrow.size=0.7,
6 edge.color="black",
7 vertex.color="red", frame=TRUE)
igraph – a package for network analysis 31
![Page 46: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/46.jpg)
Visualizing graphs
tkplot Uses Tcl/Tk via the tcltk package, interactive, 2d.
1 > id <- tkplot(g, vertex.size=4,
2 vertex.label=NA,
3 edge.color="black",
4 edge.arrow.size=0.7,
5 vertex.color="red")
6 > coords <- tkplot.getcoords(id)
igraph – a package for network analysis 32
![Page 47: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/47.jpg)
Visualizing graphs
rglplot Needs the rgl package.
1 > co <- layout.kamada.kawai(g, dim=3)
2 > rglplot(g, vertex.size=5,
3 vertex.label=NA,
4 layout=co)
igraph – a package for network analysis 33
![Page 48: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/48.jpg)
Working with a somewhat bigger graph
1 > vertices <- read.csv("http://cneurocvs.rmki.kfki.hu/igraph/judicial.csv")
2 > edges <- read.table("http://cneurocvs.rmki.kfki.hu/igraph/allcites.txt")
3 > jg <- graph.data.frame(edges, vertices=vertices, dir=TRUE)
4 > summary(jg)
5 Vertices: 30288
6 Edges: 216738
7 Directed: TRUE
8 No graph attributes.
9 Vertex attributes: name, usid, parties, year, overruled, overruling,
10 oxford, liihc, indeg, outdeg, hub, hubrank, auth, authrank, between, incent.
11 No edge attributes.
igraph – a package for network analysis 34
![Page 49: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/49.jpg)
Working with a somewhat bigger graph
1 > is.connected(jg) # Is it connected?
2 [1] FALSE
![Page 50: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/50.jpg)
Working with a somewhat bigger graph
1 > is.connected(jg) # Is it connected?
2 [1] FALSE
3
4 > no.clusters(jg) # How many components?
5 [1] 4881
![Page 51: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/51.jpg)
Working with a somewhat bigger graph
1 > is.connected(jg) # Is it connected?
2 [1] FALSE
3
4 > no.clusters(jg) # How many components?
5 [1] 4881
6
7 > table(clusters(jg)$csize) # How big are these?
8
9 1 3 4 25389
10 4871 8 1 1
![Page 52: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/52.jpg)
Working with a somewhat bigger graph
1 > is.connected(jg) # Is it connected?
2 [1] FALSE
3
4 > no.clusters(jg) # How many components?
5 [1] 4881
6
7 > table(clusters(jg)$csize) # How big are these?
8
9 1 3 4 25389
10 4871 8 1 1
11
12 > max(degree(jg, mode="in")) # Vertex degree
13 [1] 248
14 > max(degree(jg, mode="out"))
15 [1] 195
16 > max(degree(jg, mode="all"))
17 [1] 313
igraph – a package for network analysis 35
![Page 53: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/53.jpg)
Working with a somewhat bigger graph
1 # In-degree distribution
2 > plot(degree.distribution(jg, mode="in"), log="xy")
igraph – a package for network analysis 36
![Page 54: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/54.jpg)
Working with a somewhat bigger graph
1 # Out-degree distribution
2 plot(degree.distribution(jg, mode="out"), log="xy")
igraph – a package for network analysis 37
![Page 55: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/55.jpg)
Working with a somewhat bigger graph
1 # Taking the largest component
2 > cl <- clusters(jg)
3 > jg2 <- subgraph(jg, which(cl$membership == which.max(cl$csize)-1)-1)
4 > summary(jg2)
5 Vertices: 25389
6 Edges: 216718
7 Directed: TRUE
8 No graph attributes.
9 Vertex attributes: name, usid, parties, year, overruled, overruling,
10 oxford, liihc, indeg, outdeg, hub, hubrank, auth, authrank,
11 between, incent.
12 No edge attributes.
igraph – a package for network analysis 38
![Page 56: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/56.jpg)
Working with a somewhat bigger graph
1 > graph.density(jg2) # Density
2 [1] 0.0003362180
![Page 57: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/57.jpg)
Working with a somewhat bigger graph
1 > graph.density(jg2) # Density
2 [1] 0.0003362180
3
4 > transitivity(jg2) # Transitivity
5 [1] 0.1260031
![Page 58: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/58.jpg)
Working with a somewhat bigger graph
1 > graph.density(jg2) # Density
2 [1] 0.0003362180
3
4 > transitivity(jg2) # Transitivity
5 [1] 0.1260031
6
7 # Transitivity of a random graph of the same size
8 > g <- erdos.renyi.game(vcount(jg2), ecount(jg2), type="gnm")
9 > transitivity(g)
10 [1] 0.00064649
![Page 59: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/59.jpg)
Working with a somewhat bigger graph
1 > graph.density(jg2) # Density
2 [1] 0.0003362180
3
4 > transitivity(jg2) # Transitivity
5 [1] 0.1260031
6
7 # Transitivity of a random graph of the same size
8 > g <- erdos.renyi.game(vcount(jg2), ecount(jg2), type="gnm")
9 > transitivity(g)
10 [1] 0.00064649
11
12 # Transitivity of a random graph with the same degrees
13 > g2 <- degree.sequence.game(degree(jg2,mode="all"), method="vl")
14 > transitivity(g2)
15 [1] 0.004107072
igraph – a package for network analysis 39
![Page 60: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/60.jpg)
Community structure detection
1 > fc <- fastgreedy.community(simplify(as.undirected(jg2)))
2 > memb <- community.to.membership(jg2,
3 fc$merges,
4 which.max(fc$modularity))
5 > lay <- layout.drl(jg2)
6 > jg3 <- graph.empty(n=vcount(jg2))
7 > colbar <- rainbow(5)
8 > col <- colbar[memb$membership+1]
9 > col[is.na(col)] <- "grey"
10 > plot(jg3, layout=lay, vertex.size=1,
11 vertex.label=NA, asp=FALSE,
12 vertex.color=col,
13 vertex.frame.color=col)
igraph – a package for network analysis 40
![Page 61: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/61.jpg)
Functionality, what can be calculated?
Fast (millions) creating graphs (most of the time) • structural modification(add/delete edges/vertices) • subgraph • simplify •graph.decompose • degree • clusters • graph.density • is.simple,is.loop, is.multiple • articulation points and biconnected components• ARPACK stuff: page.rank, hub.score, authority.score, eigenvectorcentrality • transitivity • Burt’s constraint • dyad & triad census,graph motifs • k-cores • MST • reciprocity • modularity •closeness and (edge) betweenness estimation • shortest paths fromone source • generating Gn,p and Gn,m graphs • generating PAgraphs with various PA exponents • topological sort
Slow (10000) closeness • diameter • betweenness • all-pairs shortest paths,average path length • most layout generators •
Very slow (100) cliques • cohesive blocks • edge/vertex connectivity • maximumflows and minimum cuts • power centrality • alpha centrality •(sub)graph isomorphism
igraph – a package for network analysis 41
![Page 62: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/62.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
![Page 63: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/63.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
• Sparse matrices (Matrix package), get.adjacency and graph.adjacency supportsthem.
![Page 64: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/64.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
• Sparse matrices (Matrix package), get.adjacency and graph.adjacency supportsthem.
• sna and network R packages. Currently throught adjacency matrices. Usenamespaces!
![Page 65: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/65.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
• Sparse matrices (Matrix package), get.adjacency and graph.adjacency supportsthem.
• sna and network R packages. Currently throught adjacency matrices. Usenamespaces!
• Pajek. .net file format is supported.
![Page 66: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/66.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
• Sparse matrices (Matrix package), get.adjacency and graph.adjacency supportsthem.
• sna and network R packages. Currently throught adjacency matrices. Usenamespaces!
• Pajek. .net file format is supported.
• Visone. Use GraphML format.
![Page 67: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/67.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
• Sparse matrices (Matrix package), get.adjacency and graph.adjacency supportsthem.
• sna and network R packages. Currently throught adjacency matrices. Usenamespaces!
• Pajek. .net file format is supported.
• Visone. Use GraphML format.
• Cytoscape. Use GML format.
![Page 68: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/68.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
• Sparse matrices (Matrix package), get.adjacency and graph.adjacency supportsthem.
• sna and network R packages. Currently throught adjacency matrices. Usenamespaces!
• Pajek. .net file format is supported.
• Visone. Use GraphML format.
• Cytoscape. Use GML format.
• GraphViz. igraph can write .dot files.
![Page 69: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/69.jpg)
Connection to other network/graph software
• graph package: igraph.to.graphNEL, igraph.from.graphNEL.
• Sparse matrices (Matrix package), get.adjacency and graph.adjacency supportsthem.
• sna and network R packages. Currently throught adjacency matrices. Usenamespaces!
• Pajek. .net file format is supported.
• Visone. Use GraphML format.
• Cytoscape. Use GML format.
• GraphViz. igraph can write .dot files.
• In general. The GraphML and GML file formats are fully supported, many programs canread/write these.
igraph – a package for network analysis 42
![Page 70: igraph – a package for network analysis](https://reader031.vdocument.in/reader031/viewer/2022013013/586a1c191a28ab6b518b6d80/html5/thumbnails/70.jpg)
Acknowledgements
Tamas Nepusz
Peter McMahan, the BLISS, Walktrap, Spinglass, DrL projects
All the people who contributed code, sent bug reports, suggestions
The R project
igraph – a package for network analysis 43