library(igraph)
set.seed(1337)
# use the function read.graph to read in a network from the facebook dataset
?read.graph
g <- read.graph("facebook/0.edges", directed=F)
# use the functions vcount and ecount to get some statistics about the graph
vcount(g)
ecount(g)
# use the function simplify to remove multiple edges as well as loop edges
?simplify
g <- simplify(g, remove.multiple = T, remove.loops = T)
# did the vertex- or edge-count change?
vcount(g)
ecount(g)
# gather characteristics of the graph. obtain
# transitivity using the type "localaverage"
?transitivity
transitivity(g, type="localaverage", isolates = "zero")
# average path length
?average.path.length
average.path.length(g)
# or the degree distribution of the nodes
?degree
hist(degree(g))
# has the chosen graph components?
?components
# if it does, extract the largest component and continue with that!
comp <- components(g)
if(comp$no > 1){
larg <- which.max(comp$csize)
g <- delete.vertices(g, which(comp$membership != larg))
}
vcount(g)
ecount(g)
# obtain a community detection using the edge betweenness method
?edge.betweenness.community
commu <- edge.betweenness.community(g)
# visualize your findings using the plot function
# parameters for the plot function can be found here:
?igraph.plotting
# color the vertices according to their community membership
# and, if possible, mark the detected communities in the plot. therefore, use the parameter mark.groups
plot(g,
vertex.color = commEdBetw$membership, vertex.size = log(degree(g) + 1),
mark.groups = by(seq_along(commEdBetw$membership), commEdBetw$membership, invisible))