# Note this is a bad example for our purposes as the graph is nearly complete
# Thus you should replace this example with a different network.
################################################
## Download data from web
footballdata <- read.csv("http://www.repole.com/sun4cast/stats/cfb20140906.csv")
# To simplify things, I took 2 columns from this dataset
data <- cbind(footballdata$ScoreOff, footballdata$RushAttOff)
plot(data, asp=1)
# Create adjacency matrix by calculating distance between points
# Note I probably should have normalized the data first
Adj <- as.matrix(dist(data))
g <- graph_from_adjacency_matrix(Adj, mode="undirected", weighted = TRUE)
tkplot(g)
gsize(g) # number of edges
gorder(g) # number of vertices
deg_2 <- neighbors(g, '2') # Neighbors of vertex 2
length(deg_2) # degree of vertex 2
deg_3 <- neighbors(g, '3')
intersection(deg_2, deg_3) # vertices that are neighbors of vertex 2 and 3
farthest_vertices(g) # find the length of the longest path in the network
Degrees <- degree(g)
which.max(Degrees)
table(Degrees)
hist(Degrees, breaks=10)
# Betweeness measures how frequently the vertex lies
# on shortest paths between any two vertices in the network.
bet<- betweenness(g)
hist(bet, breaks = 20)
plot(bet)