library(igraph)
# Zachary graph
g = make_graph("Zachary")
# number of nodes
vcount(g)
## [1] 34
# average distance (degree of separation)
mean_distance(g)
## [1] 2.4082
# maximum geodesic distance (diameter)
diameter(g)
## [1] 5
# highlight the diameter
d = get_diameter(g)
V(g)$color = "white"
E(g)$color = "grey"
E(g)$width = 1
E(g, path=d)$color = "red"
E(g, path=d)$width = 2
V(g)[d]$color = "red"
plot(g, vertex.label = NA, vertex.size=5)

# histogram of distances
distance_table(g)
## $res
## [1] 78 265 137 73 8
##
## $unconnected
## [1] 0
paths = distance_table(g)$res
names(paths) = 1:length(paths)
barplot(paths / sum(paths), xlab="Distance", ylab="Frequency")
