Network Analysis in R

What are Social Networks?

  • Networks contain edges and vertices

    • Edge: lines connecting nodes

    • Vertex: dots of SN

We encode Network data in two ways:

  • Adjacency Matrix

    • 1’s next to one another are connected nodes and 0’s means no connection
  • Edge List

    • Each row represents an edge with the first col being the first vertice and the second being the connecting vertice
    library(igraph)
    ## 
    ## Attaching package: 'igraph'
    ## The following objects are masked from 'package:stats':
    ## 
    ##     decompose, spectrum
    ## The following object is masked from 'package:base':
    ## 
    ##     union
    #Create Data
    edge_list_df <- data.frame(From = c("A", "A", "A", "A", "A", "E", "F"), 
                               To = c("B", "C", "D", "E", "F", "F", "G"))
    edge_list_df
    ##   From To
    ## 1    A  B
    ## 2    A  C
    ## 3    A  D
    ## 4    A  E
    ## 5    A  F
    ## 6    E  F
    ## 7    F  G
    #Creates graph_obj
    edge_list_graph_obj <- graph_from_edgelist(as.matrix(edge_list_df), directed = FALSE)
    edge_list_graph_obj
    ## IGRAPH b1ab710 UN-- 7 7 -- 
    ## + attr: name (v/c)
    ## + edges from b1ab710 (vertex names):
    ## [1] A--B A--C A--D A--E A--F E--F F--G
    #Output Vertices: 
    vertices <- V(edge_list_graph_obj)
    cat("vertices: \n", vertices)
    ## vertices: 
    ##  1 2 3 4 5 6 7
    #Output Edges: 
    edges <- E(edge_list_graph_obj)
    cat("\n Edges: \n", edges, "\n")
    ## 
    ##  Edges: 
    ##  1 2 3 4 5 6 7
    #Determine Total Edges:
    vcount(edge_list_graph_obj)
    ## [1] 7
    #Determine Total Vertices:
    ecount(edge_list_graph_obj)
    ## [1] 7

Network Attributes

#View Network Obj " 
edge_list_graph_obj
## IGRAPH b1ab710 UN-- 7 7 -- 
## + attr: name (v/c)
## + edges from b1ab710 (vertex names):
## [1] A--B A--C A--D A--E A--F E--F F--G
#Add vertex attr:
edge_list_graph_obj <- set_vertex_attr(edge_list_graph_obj, name = "age", value = 1:7)

#Check vertex attr. 
vertex_attr(edge_list_graph_obj)
## $name
## [1] "A" "B" "C" "D" "E" "F" "G"
## 
## $age
## [1] 1 2 3 4 5 6 7
#Add edge attr. 
edge_list_graph_obj <- set_edge_attr(edge_list_graph_obj, name = "frequency", value = 7:1)

#Check edge attr.
edge_attr(edge_list_graph_obj)
## $frequency
## [1] 7 6 5 4 3 2 1

We encode information about the attributes of edges and vertices. Typically, we weigh an edge by adjusting the “relative-thickness”

### Creating Network from df :

# Load igraph package (if not already loaded)
library(igraph)

# Create edge list data frame
edge_list_df <- data.frame(from = c("A", "A", "A", "A", "A", "E", "F"),
                           to = c("B", "C", "D", "E", "F", "F", "G"))

# Add Frequency column to edge list data frame
edge.df <- cbind(edge_list_df, "Frequency" = 1:7)

# Create vertices data frame with proper column names
vertices.df <- data.frame(name = c("A", "B", "C", "D", "E", "F", "G"), 
                          age = 20:26)

# Convert 'age' column to numeric (already numeric in this case)
vertices.df$age <- as.numeric(vertices.df$age)

# Check class of 'age' column
class(vertices.df$age)
## [1] "numeric"
# Create graph from edge and vertices data frames
graph_obj <- graph_from_data_frame(d = edge.df, vertices = vertices.df, directed = FALSE)

# Plot the graph (optional, to visualize the result)
plot(graph_obj)

Subsetting with igraph obj :

#Identify Attr. 
edge_attr(graph_obj)
## $Frequency
## [1] 1 2 3 4 5 6 7
vertex_attr(graph_obj)
## $name
## [1] "A" "B" "C" "D" "E" "F" "G"
## 
## $age
## [1] 20 21 22 23 24 25 26
#Subset Edges : 
E(graph_obj)[[Frequency >= 4]]
## + 4/7 edges from 01b0696 (vertex names):
##   tail head tid hid Frequency
## 4    A    E   1   5         4
## 5    A    F   1   6         5
## 6    E    F   5   6         6
## 7    F    G   6   7         7
E(graph_obj)[[.inc("E")]] #all edges that contain vertex E
## + 2/7 edges from 01b0696 (vertex names):
##   tail head tid hid Frequency
## 4    A    E   1   5         4
## 6    E    F   5   6         6
#Subset Vertices 
V(graph_obj)[[age > 21 & name != "C"]]
## + 4/7 vertices, named, from 01b0696:
##   name age
## 4    D  23
## 5    E  24
## 6    F  25
## 7    G  26

Complex attr. :

# Set vertex colors based on age attribute
V(graph_obj)$color <- ifelse(V(graph_obj)$age >= 23, "red", "blue")

# Plot the graph with updated vertex colors
plot(graph_obj)

Network Visualization:

Picking the correct network is dependent upon what problem you are working on. Commonly adjusted features include:

  • size:

    • Emphasizes:

      • Pro:

        • Key Vertices

        • Influential Vertices (many connections)

  • labels:

    • Pro:

      • Key Vertices

      • Influential Vertices (many connections)

    • Con:

      • Becomes un=readible quickly
  • color:

    • Meant to signify categories
  • shape

    • Meant to signify categories

Igraph contains all of the common “layouts”–ie styles.

There are two common rules for network visualization:

  1. Minimize edge-crossing

  2. Vertices should NEVER overlap

  3. Edges should be equal lengths

  4. Influential nodes should be near the center

Common Layouts:

#plot(graph_obj, layout = layout.fruchterman.reingold(graph_obj))

It is recommended to test multiple layouts. Ideally the best layout is the one that minimizes the number of edges that cross each other in the network.

List of layouts:

  • layout_in_circle()

  • layout_with_fr()

  • layout_as_tree()

  • layout_nicely()

Code : Different Layouts

# Circle layout
plot(edge_list_graph_obj, vertex.label.color = "black", layout = layout_in_circle(edge_list_graph_obj))

# Fruchterman-Reingold layout
plot(edge_list_graph_obj, vertex.label.color = "black", layout = layout_with_fr(edge_list_graph_obj))

# Tree layout
m_tree <- layout_as_tree(edge_list_graph_obj)
plot(edge_list_graph_obj, vertex.label.color = "black", layout = m_tree)

# Automatically chosen layout by igraph
m_nice <- layout_nicely(edge_list_graph_obj)
plot(edge_list_graph_obj, vertex.label.color = "black", layout = m_nice)

Identifying important vertices in a network

Directed Networks:

#Det. if graph_obj is directed:
is.directed(graph_obj)
## Warning: `is.directed()` was deprecated in igraph 2.0.0.
## ℹ Please use `is_directed()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## [1] FALSE
#Det. if graph_obj is weighted:
is.weighted(graph_obj)
## Warning: `is.weighted()` was deprecated in igraph 2.0.0.
## ℹ Please use `is_weighted()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## [1] FALSE

In Network Analysis, we typically study how influential nodes are. Degree is a measure of amount of edges a vertex has for undirected-networks; for directed-networks vertices have “in-degree” and “out-degree”, both are a measure of edge frequency and direction.

We can determine:

  • Do edges exist between vertices?

Code :

#Plot Network
plot(graph_obj)

#Output for TRUE
graph_obj["B", "A"] #direction doesnt matter

## [1] 1
graph_obj["A", "B"] #direction doesnt matter
## [1] 1
#Output for no-connection
graph_obj["D", "F"] 
## [1] 0
#Output for when edge DNE: 
#graph_obj["A", "Z"] 

#Det. all edge connections:
incident(graph_obj, "A", mode = c("all")) # mode = "in" or "out" or "all"
## + 5/7 edges from 01b0696 (vertex names):
## [1] A--B A--C A--D A--E A--F
#Det. Starting Vertex of all edges:
head_of(graph_obj, E(graph_obj))
## + 7/7 vertices, named, from 01b0696:
## [1] B C D E F F G

Relationships Between Networks:

How do we evaluate the patterns between vertices between Networks?

In this section we cover:

  • identify Neighbors of vertices

  • Paths through Networks

Code : Neighbors of vertices and “common” :

#Plot Network
plot(graph_obj)

#Identify Neighbors of a given Vertex
neighbors(graph_obj, "A", mode = c("all"))
## + 5/7 vertices, named, from 01b0696:
## [1] B C D E F
#Identify Common Vertices of Network:
F_neighbors <- neighbors(graph_obj, "F", mode = c("all"))
C_neighbors <- neighbors(graph_obj, "C", mode = c("all"))

intersection(F_neighbors, C_neighbors) #Vertex of common
## + 1/7 vertex, named, from 01b0696:
## [1] A

Code : Path-Lengths :

Determine length of paths for vertices (geodesic distance).
when geodesic_distance = 1, means they are neighbors. geodesic_distance > 1, outputs the number of connections required to go between nodes. The diameter_of_a_network is the longest path in a network.

#Visualize: 
plot(graph_obj)

#Find diameter_of_network: 
diameter_of_network <- farthest_vertices(graph_obj)
diameter_of_network
## $vertices
## + 2/7 vertices, named, from 01b0696:
## [1] B G
## 
## $distance
## [1] 3
#Output longest connection:
get_diameter(graph_obj)
## + 4/7 vertices, named, from 01b0696:
## [1] B A F G

When there are multiple longest paths, we still only get one output

Code : All Vertices Reachible given steps :

#Visualize: 
plot(graph_obj)

# All Vertices Reachible given steps
ego(graph_obj, order = 1, mode = c("out"))
## [[1]]
## + 6/7 vertices, named, from 01b0696:
## [1] A B C D E F
## 
## [[2]]
## + 2/7 vertices, named, from 01b0696:
## [1] B A
## 
## [[3]]
## + 2/7 vertices, named, from 01b0696:
## [1] C A
## 
## [[4]]
## + 2/7 vertices, named, from 01b0696:
## [1] D A
## 
## [[5]]
## + 3/7 vertices, named, from 01b0696:
## [1] E A F
## 
## [[6]]
## + 4/7 vertices, named, from 01b0696:
## [1] F A E G
## 
## [[7]]
## + 2/7 vertices, named, from 01b0696:
## [1] G F

Important and Influential Vertices:

There are many measures of “important”:

  • Degree: number of connections

  • Betweenness

  • Eigen-Vector Centrality: vertices connected to vertices that are highly interconnected

  • Closeness Centrality

  • PageRank Centrality

Betweeness is how often a vertex lies at the shortest path between any two networks. This is a measure of how critical each vertex is to the flow of information through a network. High betweeness people are key-bridges between networks

#Visualize: 
plot(graph_obj)

#Det. Degree:
degree(graph_obj, mode = c("all"))
## A B C D E F G 
## 5 1 1 1 2 3 1
#Det. Betweeness:
betweenness(graph_obj, directed = FALSE)
##  A  B  C  D  E  F  G 
## 12  0  0  0  0  5  0
#Normalize Betweeness:
betweenness(graph_obj, directed = FALSE, normalized = TRUE) 
##         A         B         C         D         E         F         G 
## 0.8000000 0.0000000 0.0000000 0.0000000 0.0000000 0.3333333 0.0000000

Characterizing network structures

Eigenvector Centraliy measures how well connected a vertex is. A high Eigenvector Centraliy means this vertex is highly connected–especially to other vertexes which are themselves highly connected to other vertices.

#Visualize: 
plot(graph_obj)

#Calculate scores: 
eigen_centrality(graph_obj) #outputs many things 
## $vector
##         A         B         C         D         E         F         G 
## 1.0000000 0.3854455 0.3854455 0.3854455 0.6782950 0.7597688 0.2928495 
## 
## $value
## [1] 2.5944
## 
## $options
## $options$bmat
## [1] "I"
## 
## $options$n
## [1] 7
## 
## $options$which
## [1] "LA"
## 
## $options$nev
## [1] 1
## 
## $options$tol
## [1] 0
## 
## $options$ncv
## [1] 0
## 
## $options$ldv
## [1] 0
## 
## $options$ishift
## [1] 1
## 
## $options$maxiter
## [1] 3000
## 
## $options$nb
## [1] 1
## 
## $options$mode
## [1] 1
## 
## $options$start
## [1] 1
## 
## $options$sigma
## [1] 0
## 
## $options$sigmai
## [1] 0
## 
## $options$info
## [1] 0
## 
## $options$iter
## [1] 18
## 
## $options$nconv
## [1] 1
## 
## $options$numop
## [1] 20
## 
## $options$numopb
## [1] 0
## 
## $options$numreo
## [1] 13
eigen_centrality_obj <- eigen_centrality(graph_obj)$vector 
eigen_centrality_obj
##         A         B         C         D         E         F         G 
## 1.0000000 0.3854455 0.3854455 0.3854455 0.6782950 0.7597688 0.2928495

We can study the overall pattern of networks by not testing with: degree, betweeness or eigenvector centralty but rather, edge density. Edge density is the proportion of edges that exist in a network out of all those that could potentially exist between every pair of vertices. Simply, density is a measure of how inter-connected a network is.

#Visualize Network: 
plot(graph_obj)

#Calc Density
edge_density(graph_obj)
## [1] 0.3333333

Additionally we can measure inter-connectedness using avr-path-length. This is calculated via: mean(shortest paths between every connected vertex)

#Visualize Network: 
plot(graph_obj)

#Calc avr-path-length
 avr_path_length <- mean_distance(graph_obj, directed = FALSE)
 avr_path_length
## [1] 1.809524

Network Randomizations:

What is a random graph?

  • A random graph is a network randomly generated by an algorithm to have a set of characteristics similar to the original network.
#visualize original_network: 
original_network <- plot(graph_obj) 

#visualize random_network: 
random_network <- erdos.renyi.game(n = vcount(graph_obj),
                                   p.or.m = edge_density(graph_obj), 
                                   type = "gnp") #Eachtime we run, we get a new network

plot(random_network) 

#Notice: 
cat("Edge Density: ", edge_density(graph_obj), " N-Vertices: ", vcount(graph_obj))
## Edge Density:  0.3333333  N-Vertices:  7
cat("\n")
cat("Edge Density: ", edge_density(random_network), " N-Vertices: ", vcount(random_network), "\n")
## Edge Density:  0.3333333  N-Vertices:  7
cat("Vertices stays the same and Edge Density is approximate")
## Vertices stays the same and Edge Density is approximate

We create these simulations to test whether or not our network is unusual. We never do this by making 1 random network but rather a large amount of them then sum up and avr attributes to see how regular or irregular our networks are.

Creating 1000 random networks:

#Create storage obj: 
gl <- vector("list", 1000)

#Run simulation: 
for(i in 1:1000){
  gl[[i]] <- erdos.renyi.game(n = vcount(graph_obj),
                              p.or.m = edge_density(graph_obj), 
                              type = "gnp")
}

# Calculate means of all random networks:
avr_rand_dist <- unlist(lapply(gl, mean_distance, directed = FALSE))

# Visualize Scores:
hist(avr_rand_dist, breaks = 20)

# Add line for the original network mean
abline(
  v = mean_distance(graph_obj, directed = FALSE), 
  col = "blue",
  lty = 2,  # Dashed line
  lwd = 2
)

# Add line for the mean of random network simulations
abline(
  v = mean(avr_rand_dist),  # Mean of the random simulations
  col = "red",  # Color red for distinction
  lty = 1,  # Solid line
  lwd = 2
)

# Add smaller legend
legend("topright", 
       legend = c("Original Network Mean", "Random Network Mean"), 
       col = c("blue", "red"), 
       lty = c(2, 1), 
       lwd = 2,
       cex = 0.8)  # Adjust this value to make the legend smaller

Notice above that our network is quite typical.

Network Substructures: Triangles of a Network

  • If all edges are filed then it is said to be full
plot(graph_obj)

triangles(graph_obj) #outputs Vertices of Triangle Networks
## + 3/7 vertices, named, from 01b0696:
## [1] A F E

Global-Transitivity:

prob(adjacent vertices) is “connected”

plot(graph_obj)

#Global Transativity: 
transitivity(graph_obj)
## [1] 0.2142857

Local-Transitivity:

prop() of closed triangles a vertex is a part of out of the theoretical number of it could be a part of given its connections.

plot(graph_obj)

#Count Triangles given some Vertex (ie "A")
count_triangles(graph_obj, vids = "A")
## [1] 1
#Output Vertex's
V(graph_obj)
## + 7/7 vertices, named, from 01b0696:
## [1] A B C D E F G
#Local-Transitivity:
transitivity(graph_obj, 
             vids = "A", 
             type = "local")
##   A 
## 0.1
#Count triangles 
count_triangles(graph_obj, vids = "E")
## [1] 1
#Local Transativity: 
transitivity(graph_obj, vids ="E", type = "local")
## E 
## 1
  • Summary in Disease Terms:

    • High transitivity: Indicates that individuals who share a common contact (an infected person) are also likely to contact each other, potentially accelerating the spread of disease within tight groups like households, schools, or workplaces.
  • Low transitivity:

    • Suggests that while an individual may infect others, those individuals are less likely to be in contact with each other, which may slow the spread within local clusters but allow it to spread more broadly.

Cliques:

  • When all vertices connect to eachother it is considered to be a perfect clique. A vertex is said to be part of a clique when they all connect to eachother (ie all triangles are closed)
# Create a data frame for a clique (complete graph) with 5 nodes, and expand with additional nodes and edges
expanded_network_df <- data.frame(
  from = c("A", "A", "A", "A", "B", "B", "B", "C", "C", "D", # Clique connections (A-E)
           "F", "F", "F", "G", "G", "H", "I", "J", "J"),      # Additional connections
  to   = c("B", "C", "D", "E", "C", "D", "E", "D", "E", "E",  # Clique connections (A-E)
           "G", "H", "I", "H", "I", "I", "J", "K", "L")       # Additional connections
)

# View the data frame
print(expanded_network_df)
##    from to
## 1     A  B
## 2     A  C
## 3     A  D
## 4     A  E
## 5     B  C
## 6     B  D
## 7     B  E
## 8     C  D
## 9     C  E
## 10    D  E
## 11    F  G
## 12    F  H
## 13    F  I
## 14    G  H
## 15    G  I
## 16    H  I
## 17    I  J
## 18    J  K
## 19    J  L
expanded_network_graph_obj <- graph_from_edgelist(as.matrix(expanded_network_df), directed = FALSE)

plot(expanded_network_graph_obj)

#Largest Clique:
largest_cliques(expanded_network_graph_obj)
## [[1]]
## + 5/12 vertices, named, from d71f830:
## [1] C A E D B
#Identify cliques of any size:
max_cliques(expanded_network_graph_obj)
## [[1]]
## + 2/12 vertices, named, from d71f830:
## [1] J L
## 
## [[2]]
## + 2/12 vertices, named, from d71f830:
## [1] J K
## 
## [[3]]
## + 2/12 vertices, named, from d71f830:
## [1] J I
## 
## [[4]]
## + 4/12 vertices, named, from d71f830:
## [1] G F I H
## 
## [[5]]
## + 5/12 vertices, named, from d71f830:
## [1] C A E D B

Identifying special relationships

Close Relationships: Association & Reciprocity

Do vertices associate with random vertices or do they prefferentially associate w/ similar vertices. In other words, do birds of the same feather work together?

  • Assortativity: how likely are two vertices of similar attributes are to be attached to one another. In other words: the preferential attachment of vertices to other vertices that are similar in numeric/categorical variables (features).

    • A high-assortativity: infers birds of the same feather flock together.
#assortativity(graph_obj, values)
#values = vector{attributes associated with the vertex}

For example, consider a social network of people w/ a income attribute, it would be assortativity(graph_obj, income).

When dealing with categorical variables, you must covert them to numbers. This can be done w/ factor-levels.

Values of assortativity() range from: -1 ≤ x ≤ 1. 0 indicates no preferential attachment, +1 implies similiar individuals are only attached to other similiar individuals. -1 individuals avoid similar individuals.

When assortativity() results are significant, we must then do a test of how-significant via monte-carlo methods (ie randomization).

degree-of-assortativity: do vertices of a high-degree associate prefferentially to other vertices of a high-degree.

#assortativity.degree(graph_obj, directed = T/F)

A negative values of the a assortativity.degree() implicates highly connected individuals do not connect prefferentially to other highly connected individuals.

reciprocity: the proportion of edges that are ‘symmetrical’. In other words, the amount of edges with both ingoing & outgoing edges. reciprocity() outputs a % relative to the global quantity.

Community Detection:

If a network is said to have a ‘community-structure’ then, we may assign vertices to ‘unique-sets’. Within each community, connections between vertices are said to more dense–connections between members is stronger within communities as aposed to outside-communities.

Communities = modules = clusters

In real-world applications, communities are common.

plot(graph_obj)

fastgreedy.community(graph_obj) #comutationally demanding. Measures connection in communities relative to outside (kind-of), modularity based method, asses a modularity score after adding a vertice. Modularity score is a measure of how inter-connected within communities. 
## Warning: `fastgreedy.community()` was deprecated in igraph 2.0.0.
## ℹ Please use `cluster_fast_greedy()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## IGRAPH clustering fast greedy, groups: 2, mod: 0.2
## + groups:
##   $`1`
##   [1] "E" "F" "G"
##   
##   $`2`
##   [1] "A" "B" "C" "D"
## 
edge.betweenness.community(graph_obj) #divides the network into smaller and smaller pieces until it finds 'bridges' between communities. 
## Warning: `edge.betweenness.community()` was deprecated in igraph 2.0.0.
## ℹ Please use `cluster_edge_betweenness()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## IGRAPH clustering edge betweenness, groups: 2, mod: 0.2
## + groups:
##   $`1`
##   [1] "A" "B" "C" "D"
##   
##   $`2`
##   [1] "E" "F" "G"
## 
#length(), sizes(), membership()

#plot communities by color: plot(communty, graph_obj)

plot(fastgreedy.community(graph_obj) , graph_obj)

plot(edge.betweenness.community(graph_obj), graph_obj)

Interactive Network Visualizations:

summary(graph_obj)

range(V(graph_obj)$age)

if(!require(threejs)){
  install.packages("threejs")
}
## Loading required package: threejs
library(threejs) #allows u to zoom in and out and move vertices. 
graphjs(graph_obj)
#adding attributes:
set_vertex_attr(graph_obj, 
                "age", 
                value = V(graph_obj)$age
                  )
## IGRAPH 01b0696 UN-- 7 7 -- 
## + attr: name (v/c), age (v/n), color (v/c), Frequency (e/n)
## + edges from 01b0696 (vertex names):
## [1] A--B A--C A--D A--E A--F E--F F--G
graphjs(graph_obj)
# Create new graph obj: 
g <- make_graph(edges = c(1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2, 4, 2, 1, 4, 5, 2, 1, 3, 4), directed = FALSE)

# Simplify the graph to remove multi-edges and loops (self-edges)
g <- simplify(g, remove.multiple = TRUE, remove.loops = TRUE)

# Detect communities using the fast greedy algorithm
communities <- cluster_fast_greedy(g)

# Get community membership (which community each node belongs to)
membership <- membership(communities)

# Assign colors to communities
# We will assign the colors "yellow", "blue", and "red" to different communities
colors <- c("yellow", "blue", "red")[membership]

# Set the vertex attribute 'color' based on community membership
g <- set_vertex_attr(g, "color", value = colors)

graphjs(g)

Func. Summary:

#Every function in igraph: 
ls("package:igraph")
##   [1] "%--%"                             "%->%"                            
##   [3] "%<-%"                             "%>%"                             
##   [5] "%c%"                              "%du%"                            
##   [7] "%m%"                              "%s%"                             
##   [9] "%u%"                              "add_edges"                       
##  [11] "add_layout_"                      "add_shape"                       
##  [13] "add_vertices"                     "add.edges"                       
##  [15] "add.vertex.shape"                 "add.vertices"                    
##  [17] "adhesion"                         "adjacent_vertices"               
##  [19] "adjacent.triangles"               "aging.ba.game"                   
##  [21] "aging.barabasi.game"              "aging.prefatt.game"              
##  [23] "algorithm"                        "all_shortest_paths"              
##  [25] "all_simple_paths"                 "alpha_centrality"                
##  [27] "alpha.centrality"                 "any_loop"                        
##  [29] "any_multiple"                     "are_adjacent"                    
##  [31] "are.connected"                    "arpack"                          
##  [33] "arpack_defaults"                  "articulation_points"             
##  [35] "articulation.points"              "as_adj"                          
##  [37] "as_adj_edge_list"                 "as_adj_list"                     
##  [39] "as_adjacency_matrix"              "as_biadjacency_matrix"           
##  [41] "as_bipartite"                     "as_data_frame"                   
##  [43] "as_edgelist"                      "as_graphnel"                     
##  [45] "as_ids"                           "as_incidence_matrix"             
##  [47] "as_long_data_frame"               "as_membership"                   
##  [49] "as_phylo"                         "as_star"                         
##  [51] "as_tree"                          "as.directed"                     
##  [53] "as.igraph"                        "as.undirected"                   
##  [55] "assortativity"                    "assortativity_degree"            
##  [57] "assortativity_nominal"            "assortativity.degree"            
##  [59] "assortativity.nominal"            "asym_pref"                       
##  [61] "asymmetric.preference.game"       "atlas"                           
##  [63] "authority_score"                  "authority.score"                 
##  [65] "autocurve.edges"                  "automorphism_group"              
##  [67] "automorphisms"                    "average_local_efficiency"        
##  [69] "average.path.length"              "ba.game"                         
##  [71] "barabasi.game"                    "betweenness"                     
##  [73] "betweenness.estimate"             "bfs"                             
##  [75] "bibcoupling"                      "biconnected_components"          
##  [77] "biconnected.components"           "bipartite"                       
##  [79] "bipartite_graph"                  "bipartite_mapping"               
##  [81] "bipartite_projection"             "bipartite_projection_size"       
##  [83] "bipartite.mapping"                "bipartite.projection"            
##  [85] "bipartite.projection.size"        "bipartite.random.game"           
##  [87] "blockGraphs"                      "blocks"                          
##  [89] "bonpow"                           "bridges"                         
##  [91] "callaway.traits.game"             "canonical_permutation"           
##  [93] "canonical.permutation"            "categorical_pal"                 
##  [95] "centr_betw"                       "centr_betw_tmax"                 
##  [97] "centr_clo"                        "centr_clo_tmax"                  
##  [99] "centr_degree"                     "centr_degree_tmax"               
## [101] "centr_eigen"                      "centr_eigen_tmax"                
## [103] "centralization.betweenness"       "centralization.betweenness.tmax" 
## [105] "centralization.closeness"         "centralization.closeness.tmax"   
## [107] "centralization.degree"            "centralization.degree.tmax"      
## [109] "centralization.evcent"            "centralization.evcent.tmax"      
## [111] "centralize"                       "centralize.scores"               
## [113] "chordal_ring"                     "cit_cit_types"                   
## [115] "cit_types"                        "cited.type.game"                 
## [117] "citing.cited.type.game"           "clique_num"                      
## [119] "clique_size_counts"               "clique.number"                   
## [121] "cliques"                          "closeness"                       
## [123] "closeness.estimate"               "cluster_edge_betweenness"        
## [125] "cluster_fast_greedy"              "cluster_fluid_communities"       
## [127] "cluster_infomap"                  "cluster_label_prop"              
## [129] "cluster_leading_eigen"            "cluster_leiden"                  
## [131] "cluster_louvain"                  "cluster_optimal"                 
## [133] "cluster_spinglass"                "cluster_walktrap"                
## [135] "cluster.distribution"             "clusters"                        
## [137] "cocitation"                       "code_len"                        
## [139] "code.length"                      "cohesion"                        
## [141] "cohesive_blocks"                  "cohesive.blocks"                 
## [143] "communities"                      "compare"                         
## [145] "complementer"                     "component_distribution"          
## [147] "component_wise"                   "components"                      
## [149] "compose"                          "connect"                         
## [151] "connect.neighborhood"             "consensus_tree"                  
## [153] "console"                          "constraint"                      
## [155] "contract"                         "contract.vertices"               
## [157] "convex_hull"                      "convex.hull"                     
## [159] "coreness"                         "count_automorphisms"             
## [161] "count_components"                 "count_isomorphisms"              
## [163] "count_max_cliques"                "count_motifs"                    
## [165] "count_multiple"                   "count_subgraph_isomorphisms"     
## [167] "count_triangles"                  "count.multiple"                  
## [169] "create.communities"               "crossing"                        
## [171] "curve_multiple"                   "cut_at"                          
## [173] "cutat"                            "de_bruijn_graph"                 
## [175] "decompose"                        "decompose.graph"                 
## [177] "degree"                           "degree_distribution"             
## [179] "degree.distribution"              "degree.sequence.game"            
## [181] "degseq"                           "delete_edge_attr"                
## [183] "delete_edges"                     "delete_graph_attr"               
## [185] "delete_vertex_attr"               "delete_vertices"                 
## [187] "delete.edges"                     "delete.vertices"                 
## [189] "dendPlot"                         "dfs"                             
## [191] "diameter"                         "difference"                      
## [193] "dim_select"                       "directed_graph"                  
## [195] "disjoint_union"                   "distance_table"                  
## [197] "distances"                        "diverging_pal"                   
## [199] "diversity"                        "dominator_tree"                  
## [201] "dominator.tree"                   "dot_product"                     
## [203] "drl_defaults"                     "dyad_census"                     
## [205] "dyad.census"                      "E"                               
## [207] "E<-"                              "each_edge"                       
## [209] "eccentricity"                     "ecount"                          
## [211] "edge"                             "edge_attr"                       
## [213] "edge_attr_names"                  "edge_attr<-"                     
## [215] "edge_betweenness"                 "edge_connectivity"               
## [217] "edge_density"                     "edge_disjoint_paths"             
## [219] "edge.attributes"                  "edge.attributes<-"               
## [221] "edge.betweenness"                 "edge.betweenness.community"      
## [223] "edge.betweenness.estimate"        "edge.connectivity"               
## [225] "edge.disjoint.paths"              "edges"                           
## [227] "ego"                              "ego_size"                        
## [229] "eigen_centrality"                 "embed_adjacency_matrix"          
## [231] "embed_laplacian_matrix"           "empty_graph"                     
## [233] "ends"                             "erdos.renyi.game"                
## [235] "establishment.game"               "estimate_betweenness"            
## [237] "estimate_closeness"               "estimate_edge_betweenness"       
## [239] "eulerian_cycle"                   "eulerian_path"                   
## [241] "evcent"                           "export_pajek"                    
## [243] "exportPajek"                      "farthest_vertices"               
## [245] "farthest.nodes"                   "fastgreedy.community"            
## [247] "feedback_arc_set"                 "fit_hrg"                         
## [249] "fit_power_law"                    "forest.fire.game"                
## [251] "from_adjacency"                   "from_data_frame"                 
## [253] "from_edgelist"                    "from_incidence_matrix"           
## [255] "from_literal"                     "from_prufer"                     
## [257] "full_bipartite_graph"             "full_citation_graph"             
## [259] "full_graph"                       "get_diameter"                    
## [261] "get.adjacency"                    "get.adjedgelist"                 
## [263] "get.adjlist"                      "get.all.shortest.paths"          
## [265] "get.data.frame"                   "get.diameter"                    
## [267] "get.edge"                         "get.edge.attribute"              
## [269] "get.edge.ids"                     "get.edgelist"                    
## [271] "get.edges"                        "get.graph.attribute"             
## [273] "get.incidence"                    "get.shortest.paths"              
## [275] "get.stochastic"                   "get.vertex.attribute"            
## [277] "getIgraphOpt"                     "girth"                           
## [279] "global_efficiency"                "gnm"                             
## [281] "gnp"                              "gorder"                          
## [283] "graph"                            "graph_"                          
## [285] "graph_attr"                       "graph_attr_names"                
## [287] "graph_attr<-"                     "graph_from_adj_list"             
## [289] "graph_from_adjacency_matrix"      "graph_from_atlas"                
## [291] "graph_from_biadjacency_matrix"    "graph_from_data_frame"           
## [293] "graph_from_edgelist"              "graph_from_graphdb"              
## [295] "graph_from_graphnel"              "graph_from_incidence_matrix"     
## [297] "graph_from_isomorphism_class"     "graph_from_lcf"                  
## [299] "graph_from_literal"               "graph_id"                        
## [301] "graph_version"                    "graph.adhesion"                  
## [303] "graph.adjacency"                  "graph.adjlist"                   
## [305] "graph.atlas"                      "graph.attributes"                
## [307] "graph.attributes<-"               "graph.automorphisms"             
## [309] "graph.bfs"                        "graph.bipartite"                 
## [311] "graph.cohesion"                   "graph.complementer"              
## [313] "graph.compose"                    "graph.coreness"                  
## [315] "graph.count.isomorphisms.vf2"     "graph.count.subisomorphisms.vf2" 
## [317] "graph.data.frame"                 "graph.de.bruijn"                 
## [319] "graph.density"                    "graph.dfs"                       
## [321] "graph.difference"                 "graph.disjoint.union"            
## [323] "graph.diversity"                  "graph.edgelist"                  
## [325] "graph.eigen"                      "graph.empty"                     
## [327] "graph.extended.chordal.ring"      "graph.famous"                    
## [329] "graph.formula"                    "graph.full"                      
## [331] "graph.full.bipartite"             "graph.full.citation"             
## [333] "graph.get.isomorphisms.vf2"       "graph.get.subisomorphisms.vf2"   
## [335] "graph.graphdb"                    "graph.incidence"                 
## [337] "graph.intersection"               "graph.isoclass"                  
## [339] "graph.isoclass.subgraph"          "graph.isocreate"                 
## [341] "graph.isomorphic"                 "graph.isomorphic.bliss"          
## [343] "graph.isomorphic.vf2"             "graph.kautz"                     
## [345] "graph.knn"                        "graph.laplacian"                 
## [347] "graph.lattice"                    "graph.lcf"                       
## [349] "graph.maxflow"                    "graph.mincut"                    
## [351] "graph.motifs"                     "graph.motifs.est"                
## [353] "graph.motifs.no"                  "graph.neighborhood"              
## [355] "graph.ring"                       "graph.star"                      
## [357] "graph.strength"                   "graph.subisomorphic.lad"         
## [359] "graph.subisomorphic.vf2"          "graph.tree"                      
## [361] "graph.union"                      "graphlet_basis"                  
## [363] "graphlet_proj"                    "graphlets"                       
## [365] "graphlets.candidate.basis"        "graphlets.project"               
## [367] "graphs_from_cohesive_blocks"      "greedy_vertex_coloring"          
## [369] "grg"                              "grg.game"                        
## [371] "groups"                           "growing"                         
## [373] "growing.random.game"              "gsize"                           
## [375] "harmonic_centrality"              "has_eulerian_cycle"              
## [377] "has_eulerian_path"                "has.multiple"                    
## [379] "head_of"                          "head_print"                      
## [381] "hierarchical_sbm"                 "hierarchy"                       
## [383] "hrg"                              "hrg_tree"                        
## [385] "hrg.consensus"                    "hrg.create"                      
## [387] "hrg.dendrogram"                   "hrg.fit"                         
## [389] "hrg.game"                         "hrg.predict"                     
## [391] "hub_score"                        "hub.score"                       
## [393] "identical_graphs"                 "igraph_demo"                     
## [395] "igraph_opt"                       "igraph_options"                  
## [397] "igraph_test"                      "igraph_version"                  
## [399] "igraph.console"                   "igraph.drl.coarsen"              
## [401] "igraph.drl.coarsest"              "igraph.drl.default"              
## [403] "igraph.drl.final"                 "igraph.drl.refine"               
## [405] "igraph.from.graphNEL"             "igraph.options"                  
## [407] "igraph.sample"                    "igraph.shape.noclip"             
## [409] "igraph.shape.noplot"              "igraph.to.graphNEL"              
## [411] "igraph.version"                   "igraphdemo"                      
## [413] "igraphtest"                       "in_circle"                       
## [415] "incident"                         "incident_edges"                  
## [417] "indent_print"                     "independence.number"             
## [419] "independent.vertex.sets"          "induced_subgraph"                
## [421] "induced.subgraph"                 "infomap.community"               
## [423] "interconnected.islands.game"      "intersection"                    
## [425] "is_acyclic"                       "is_biconnected"                  
## [427] "is_bipartite"                     "is_chordal"                      
## [429] "is_connected"                     "is_dag"                          
## [431] "is_degseq"                        "is_directed"                     
## [433] "is_forest"                        "is_graphical"                    
## [435] "is_hierarchical"                  "is_igraph"                       
## [437] "is_isomorphic_to"                 "is_matching"                     
## [439] "is_max_matching"                  "is_min_separator"                
## [441] "is_named"                         "is_printer_callback"             
## [443] "is_separator"                     "is_simple"                       
## [445] "is_subgraph_isomorphic_to"        "is_tree"                         
## [447] "is_weighted"                      "is.bipartite"                    
## [449] "is.chordal"                       "is.connected"                    
## [451] "is.dag"                           "is.degree.sequence"              
## [453] "is.directed"                      "is.graphical.degree.sequence"    
## [455] "is.hierarchical"                  "is.igraph"                       
## [457] "is.loop"                          "is.matching"                     
## [459] "is.maximal.matching"              "is.minimal.separator"            
## [461] "is.multiple"                      "is.mutual"                       
## [463] "is.named"                         "is.separator"                    
## [465] "is.simple"                        "is.weighted"                     
## [467] "isomorphic"                       "isomorphism_class"               
## [469] "isomorphisms"                     "ivs"                             
## [471] "ivs_size"                         "k_shortest_paths"                
## [473] "k.regular.game"                   "kautz_graph"                     
## [475] "keeping_degseq"                   "knn"                             
## [477] "label.propagation.community"      "laplacian_matrix"                
## [479] "largest_cliques"                  "largest_component"               
## [481] "largest_ivs"                      "largest_weighted_cliques"        
## [483] "largest.cliques"                  "largest.independent.vertex.sets" 
## [485] "last_cit"                         "lastcit.game"                    
## [487] "lattice"                          "layout_"                         
## [489] "layout_as_bipartite"              "layout_as_star"                  
## [491] "layout_as_tree"                   "layout_components"               
## [493] "layout_in_circle"                 "layout_nicely"                   
## [495] "layout_on_grid"                   "layout_on_sphere"                
## [497] "layout_randomly"                  "layout_with_dh"                  
## [499] "layout_with_drl"                  "layout_with_fr"                  
## [501] "layout_with_gem"                  "layout_with_graphopt"            
## [503] "layout_with_kk"                   "layout_with_lgl"                 
## [505] "layout_with_mds"                  "layout_with_sugiyama"            
## [507] "layout.auto"                      "layout.bipartite"                
## [509] "layout.circle"                    "layout.davidson.harel"           
## [511] "layout.drl"                       "layout.fruchterman.reingold"     
## [513] "layout.fruchterman.reingold.grid" "layout.gem"                      
## [515] "layout.graphopt"                  "layout.grid"                     
## [517] "layout.grid.3d"                   "layout.kamada.kawai"             
## [519] "layout.lgl"                       "layout.mds"                      
## [521] "layout.merge"                     "layout.norm"                     
## [523] "layout.random"                    "layout.reingold.tilford"         
## [525] "layout.sphere"                    "layout.spring"                   
## [527] "layout.star"                      "layout.sugiyama"                 
## [529] "layout.svd"                       "leading.eigenvector.community"   
## [531] "line_graph"                       "line.graph"                      
## [533] "list.edge.attributes"             "list.graph.attributes"           
## [535] "list.vertex.attributes"           "local_efficiency"                
## [537] "local_scan"                       "make_"                           
## [539] "make_bipartite_graph"             "make_chordal_ring"               
## [541] "make_clusters"                    "make_de_bruijn_graph"            
## [543] "make_directed_graph"              "make_ego_graph"                  
## [545] "make_empty_graph"                 "make_from_prufer"                
## [547] "make_full_bipartite_graph"        "make_full_citation_graph"        
## [549] "make_full_graph"                  "make_graph"                      
## [551] "make_kautz_graph"                 "make_lattice"                    
## [553] "make_line_graph"                  "make_neighborhood_graph"         
## [555] "make_ring"                        "make_star"                       
## [557] "make_tree"                        "make_undirected_graph"           
## [559] "match_vertices"                   "max_bipartite_match"             
## [561] "max_cardinality"                  "max_cliques"                     
## [563] "max_cohesion"                     "max_flow"                        
## [565] "maxcohesion"                      "maximal_ivs"                     
## [567] "maximal.cliques"                  "maximal.cliques.count"           
## [569] "maximal.independent.vertex.sets"  "maximum.bipartite.matching"      
## [571] "maximum.cardinality.search"       "mean_distance"                   
## [573] "membership"                       "merge_coords"                    
## [575] "merges"                           "min_cut"                         
## [577] "min_separators"                   "min_st_separators"               
## [579] "minimal.st.separators"            "minimum.size.separators"         
## [581] "minimum.spanning.tree"            "mod.matrix"                      
## [583] "modularity"                       "modularity_matrix"               
## [585] "motifs"                           "mst"                             
## [587] "multilevel.community"             "neighborhood"                    
## [589] "neighborhood_size"                "neighborhood.size"               
## [591] "neighbors"                        "nicely"                          
## [593] "no.clusters"                      "norm_coords"                     
## [595] "normalize"                        "on_grid"                         
## [597] "on_sphere"                        "optimal.community"               
## [599] "pa"                               "pa_age"                          
## [601] "page_rank"                        "page.rank"                       
## [603] "parent"                           "path"                            
## [605] "path.length.hist"                 "permute"                         
## [607] "permute.vertices"                 "piecewise.layout"                
## [609] "plot_dendrogram"                  "plot_hierarchy"                  
## [611] "plot.igraph"                      "plotHierarchy"                   
## [613] "power_centrality"                 "power.law.fit"                   
## [615] "predict_edges"                    "pref"                            
## [617] "preference.game"                  "print_all"                       
## [619] "print.igraph"                     "printer_callback"                
## [621] "r_pal"                            "radius"                          
## [623] "random_edge_walk"                 "random_walk"                     
## [625] "random.graph.game"                "randomly"                        
## [627] "read_graph"                       "read.graph"                      
## [629] "realize_bipartite_degseq"         "realize_degseq"                  
## [631] "reciprocity"                      "remove.edge.attribute"           
## [633] "remove.graph.attribute"           "remove.vertex.attribute"         
## [635] "reverse_edges"                    "rewire"                          
## [637] "rglplot"                          "ring"                            
## [639] "running_mean"                     "running.mean"                    
## [641] "sample_"                          "sample_asym_pref"                
## [643] "sample_bipartite"                 "sample_cit_cit_types"            
## [645] "sample_cit_types"                 "sample_correlated_gnp"           
## [647] "sample_correlated_gnp_pair"       "sample_degseq"                   
## [649] "sample_dirichlet"                 "sample_dot_product"              
## [651] "sample_fitness"                   "sample_fitness_pl"               
## [653] "sample_forestfire"                "sample_gnm"                      
## [655] "sample_gnp"                       "sample_grg"                      
## [657] "sample_growing"                   "sample_hierarchical_sbm"         
## [659] "sample_hrg"                       "sample_islands"                  
## [661] "sample_k_regular"                 "sample_last_cit"                 
## [663] "sample_motifs"                    "sample_pa"                       
## [665] "sample_pa_age"                    "sample_pref"                     
## [667] "sample_sbm"                       "sample_seq"                      
## [669] "sample_smallworld"                "sample_spanning_tree"            
## [671] "sample_sphere_surface"            "sample_sphere_volume"            
## [673] "sample_traits"                    "sample_traits_callaway"          
## [675] "sample_tree"                      "sbm"                             
## [677] "sbm.game"                         "scan_stat"                       
## [679] "sequential_pal"                   "set_edge_attr"                   
## [681] "set_graph_attr"                   "set_vertex_attr"                 
## [683] "set.edge.attribute"               "set.graph.attribute"             
## [685] "set.vertex.attribute"             "shape_noclip"                    
## [687] "shape_noplot"                     "shapes"                          
## [689] "shortest_paths"                   "shortest.paths"                  
## [691] "show_trace"                       "showtrace"                       
## [693] "similarity"                       "similarity.dice"                 
## [695] "similarity.invlogweighted"        "similarity.jaccard"              
## [697] "simplified"                       "simplify"                        
## [699] "simplify_and_colorize"            "sir"                             
## [701] "sizes"                            "smallworld"                      
## [703] "spectrum"                         "spinglass.community"             
## [705] "split_join_distance"              "st_cuts"                         
## [707] "st_min_cuts"                      "star"                            
## [709] "static.fitness.game"              "static.power.law.game"           
## [711] "stCuts"                           "stMincuts"                       
## [713] "stochastic_matrix"                "strength"                        
## [715] "subcomponent"                     "subgraph"                        
## [717] "subgraph_centrality"              "subgraph_isomorphic"             
## [719] "subgraph_isomorphisms"            "subgraph.centrality"             
## [721] "subgraph.edges"                   "tail_of"                         
## [723] "time_bins"                        "tk_canvas"                       
## [725] "tk_center"                        "tk_close"                        
## [727] "tk_coords"                        "tk_fit"                          
## [729] "tk_off"                           "tk_postscript"                   
## [731] "tk_reshape"                       "tk_rotate"                       
## [733] "tk_set_coords"                    "tkigraph"                        
## [735] "tkplot"                           "tkplot.canvas"                   
## [737] "tkplot.center"                    "tkplot.close"                    
## [739] "tkplot.export.postscript"         "tkplot.fit.to.screen"            
## [741] "tkplot.getcoords"                 "tkplot.off"                      
## [743] "tkplot.reshape"                   "tkplot.rotate"                   
## [745] "tkplot.setcoords"                 "to_prufer"                       
## [747] "topo_sort"                        "topological.sort"                
## [749] "traits"                           "traits_callaway"                 
## [751] "transitivity"                     "tree"                            
## [753] "triad_census"                     "triad.census"                    
## [755] "triangles"                        "undirected_graph"                
## [757] "unfold_tree"                      "unfold.tree"                     
## [759] "union"                            "upgrade_graph"                   
## [761] "V"                                "V<-"                             
## [763] "vcount"                           "vertex"                          
## [765] "vertex_attr"                      "vertex_attr_names"               
## [767] "vertex_attr<-"                    "vertex_connectivity"             
## [769] "vertex_disjoint_paths"            "vertex.attributes"               
## [771] "vertex.attributes<-"              "vertex.connectivity"             
## [773] "vertex.disjoint.paths"            "vertex.shapes"                   
## [775] "vertices"                         "voronoi_cells"                   
## [777] "walktrap.community"               "watts.strogatz.game"             
## [779] "weighted_clique_num"              "weighted_cliques"                
## [781] "which_loop"                       "which_multiple"                  
## [783] "which_mutual"                     "with_dh"                         
## [785] "with_drl"                         "with_edge_"                      
## [787] "with_fr"                          "with_gem"                        
## [789] "with_graph_"                      "with_graphopt"                   
## [791] "with_igraph_opt"                  "with_kk"                         
## [793] "with_lgl"                         "with_mds"                        
## [795] "with_sugiyama"                    "with_vertex_"                    
## [797] "without_attr"                     "without_loops"                   
## [799] "without_multiples"                "write_graph"                     
## [801] "write.graph"

1. graph.edgelist()

  • Converts an edge list (matrix) to an igraph object.
  • Arguments:
    • edges: Matrix or data frame of edges.
    • directed: Specifies if the graph is directed (TRUE or FALSE).
  • Use case: Converts relationships in a data frame or matrix to a network graph.

2. V(g) and E(g)

  • V(g): Accesses vertices (nodes) of a graph.
  • E(g): Accesses edges of a graph.
  • Use case: Explore nodes and edges in a network.

3. ecount(g) and vcount(g)

  • ecount(g): Returns the number of edges in the graph.
  • vcount(g): Returns the number of vertices in the graph.
  • Use case: Quick overview of graph size (nodes and edges).

4. set_vertex_attr()

  • Sets attributes for the vertices.
  • Arguments:
    • graph: The graph object.
    • name: Name of the vertex attribute.
    • value: Values assigned to vertices.
  • Use case: Assign attributes like gender, age, etc., to vertices.

5. set_edge_attr()

  • Sets attributes for the edges.
  • Arguments:
    • graph: The graph object.
    • name: Name of the edge attribute.
    • value: Values assigned to edges.
  • Use case: Assign attributes such as weight or contact hours to edges.

6. graph_from_data_frame()

  • Creates a graph from data frames of edges and vertices.
  • Arguments:
    • d: Data frame of edges.
    • vertices: Data frame of vertex attributes.
    • directed: Specifies if the graph is directed.
  • Use case: Creates a graph object from data.

7. layout_in_circle()

  • Positions vertices in a circle for plotting.
  • Use case: Visualizes relationships in a circular layout for clarity.

8. layout_with_fr()

  • Fruchterman-Reingold force-directed layout for better visualization.
  • Use case: Spreads out vertices based on edge connections.

9. layout_as_tree()

  • Arranges the vertices hierarchically in a tree structure.
  • Use case: Useful for visualizing hierarchical or tree-like structures.

10. layout_nicely()

  • Automatically chooses a suitable layout for plotting a graph.
  • Use case: When you’re unsure which layout to use, this function selects one for optimal visualization.

11. delete_edges()

  • Deletes specific edges from the graph.
  • Arguments:
    • graph: The graph object.
    • edges: Condition for edge removal (e.g., weight less than a threshold).
  • Use case: Remove edges based on conditions, like contact hours below a certain threshold.

12. incident()

  • Identifies edges incident to a given vertex.
  • Arguments:
    • graph: The graph object.
    • v: The vertex of interest.
    • mode: Direction of edges (all, out, in).
  • Use case: Analyzing edges connected to a particular individual in the network.

13. neighbors()

  • Identifies neighboring vertices for a given vertex.
  • Arguments:
    • graph: The graph object.
    • v: The vertex of interest.
    • mode: Direction of neighbors (all, out, in).
  • Use case: Identifies individuals in proximity to a certain person in a disease spread.

14. intersection()

  • Finds vertices common between two vertex sets.
  • Use case: Useful for identifying mutual connections between two vertices.

15. farthest_vertices()

  • Identifies the two vertices that are furthest apart in the graph.
  • Use case: Useful in analyzing the extreme range of connections.

16. get_diameter()

  • Finds the path (sequence of vertices) between the two vertices furthest apart.
  • Use case: Useful for exploring the longest connection path in a network.

17. ego()

  • Creates an ego graph, showing vertices reachable within a certain number of steps.
  • Arguments:
    • graph: The graph object.
    • order: Number of steps (connections) to consider.
    • v: The central vertex of the ego graph.
    • mode: Direction of edges to consider.
  • Use case: Identify individuals connected within a few steps from a central person.

18. degree()

  • Calculates the degree (number of connections) of vertices.
  • Arguments:
    • graph: The graph object.
    • mode: Direction of connections (out, in, or all).
  • Use case: Understand how many people each individual is connected to.

19. betweenness()

  • Measures the centrality of vertices based on shortest paths.
  • Arguments:
    • graph: The graph object.
    • directed: Specifies if the graph is directed.
  • Use case: Identifies individuals who act as bridges in the spread of disease.

20. make_ego_graph()

  • Creates a subgraph centered on a specific vertex and includes vertices within a certain radius.
  • Arguments:
    • graph: The original graph.
    • order: The radius (or number of steps) from the vertex of interest.
    • nodes: The vertex of interest.
    • mode: Specifies the direction of connections.
  • Use case: Create a subgraph of individuals connected to a central person, like patient zero.

21. distances()

  • Computes the shortest path distances between vertices.
  • Arguments:
    • graph: The graph object.
    • v: The source vertex.
    • to: The target vertex.
    • mode: Specifies direction of edges to consider.
  • Use case: Helps analyze how far individuals are from patient zero.

22. plot()

  • Visualizes the graph with various options for customization.
  • Arguments:
    • graph: The graph object.
    • vertex.label: Labels for the vertices.
    • vertex.label.color: Color of vertex labels.
    • edge.color: Color of edges.
    • vertex.size: Size of the vertices.
    • edge.arrow.size: Size of the arrow on edges.
    • layout: Layout of the graph.
  • Use case: Visualize the network to explore relationships, central nodes, or disease spread paths.

23. assortativity()

  • Measures how preferentially vertices attach to other vertices with the same attribute (e.g., gender, degree).
  • Arguments:
    • graph: The graph object.
    • types1: Numeric vector of vertex attributes (e.g., gender, profession).
  • Use case: Analyze social behavior or structural patterns in networks, such as gender homophily in friendship networks.

assortativity(g1, types1 = values)

24. assortativity.degree()

  • Calculates the assortativity based on vertex degrees.
  • Arguments:
    • graph: The graph object.
    • directed: Logical, whether to consider the graph directed.
  • Use case: Assess if individuals with similar numbers of connections (degree) are more likely to be linked in a social network.

assortativity.degree(g1, directed = FALSE)

25. fastgreedy.community()

  • Detects communities in a graph using the fast-greedy optimization of modularity.
  • Arguments:
    • graph: The graph object.
  • Use case: Identify and analyze sub-communities or clusters in large social networks.

kc <- fastgreedy.community(g)

26. edge.betweenness.community()

  • Uses edge betweenness to detect communities in a graph. Edges with high betweenness are more likely to be bridges between communities and are removed.
  • Arguments:
    • graph: The graph object.
  • Use case: Explore different community structures within a network.

gc <- edge.betweenness.community(g)

27. graphjs() (from the threejs package)

  • Creates a 3D, interactive network graph visualization.
  • Arguments:
    • graph: The igraph object.
    • vertex.size: Adjusts the size of the vertices.
    • vertex.color: Specifies vertex colors.
  • Use case: Create visually interactive network graphs for better understanding and exploration.

graphjs(g, vertex.size = 1, vertex.color = “dodgerblue”)

28. eigen_centrality()

  • Computes the eigenvector centrality of the vertices in the graph. Vertices with high eigenvector centrality are connected to other well-connected vertices.
  • Arguments:
    • graph: The graph object.
    • directed: Logical, whether to consider the graph directed.
  • Use case: Identify the most influential individuals in a social network.

ec <- eigen_centrality(g)$vector

29. graph_from_adjacency_matrix()

  • Converts an adjacency matrix to a graph object.
  • Arguments:
    • adjmatrix: A numeric matrix representing the adjacency structure.
    • mode: Specifies the type of edges (directed or undirected).
  • Use case: Convert matrix data into a graph for further analysis or visualization.

g <- graph_from_adjacency_matrix(adjmatrix, mode = “undirected”)

30. simplify()

  • Removes multiple edges and loops from a graph.
  • Arguments:
    • graph: The graph object.
    • remove.multiple: Logical, whether to remove multiple edges.
    • remove.loops: Logical, whether to remove loops.
  • Use case: Clean up graphs by removing redundant or irrelevant connections.

g <- simplify(g, remove.multiple = TRUE, remove.loops = TRUE)

31. degree_distribution()

  • Computes the distribution of vertex degrees.
  • Arguments:
    • graph: The graph object.
  • Use case: Understand the connectivity patterns in a network, such as the presence of highly connected hubs.

deg_dist <- degree_distribution(g)

32. closeness()

  • Measures how close a vertex is to all other vertices in the graph, based on the shortest paths.
  • Arguments:
    • graph: The graph object.
  • Use case: Identify the individuals who can quickly reach others in a communication network.

cl <- closeness(g)

33. transitivity()

  • Calculates the clustering coefficient of the graph, which measures the likelihood that two neighbors of a vertex are also connected.
  • Arguments:
    • graph: The graph object.
    • type: Type of transitivity to calculate (“global”, “local”, or “average”).
  • Use case: Assess the degree of clustering or small-world phenomena in social networks.

trans <- transitivity(g, type = “global”)

34. diameter()

  • Returns the length of the longest shortest path between any two vertices in the graph.
  • Arguments:
    • graph: The graph object.
  • Use case: Analyze the maximum distance between two individuals in a social network.

dia <- diameter(g)

35. subgraph()

  • Creates a subgraph induced by the specified vertices.
  • Arguments:
    • graph: The graph object.
    • v: A vector of vertex indices.
  • Use case: Focus on a smaller part of the network for detailed analysis.

subg <- induced_subgraph(g, v = c(1, 2, 3))