Certainly! You can perform several basic network analyses on your graph using the igraph package in R. Below are some key analyses and visualizations to understand the distribution of nodes and the number of links (degree distribution):
1. Basic Network Summary
First, check the basic properties of your graph:
summary(graph)
This will give you:
- Number of nodes (vertices)
- Number of edges (links)
- Whether the graph is directed or undirected
2. Degree Distribution (Most Connected Nodes)
The degree of a node is the number of connections it has. For a directed graph, you can compute:
- In-degree (number of incoming links)
- Out-degree (number of outgoing links)
- Total degree (sum of in and out degrees)
# Calculate degrees
degree_in <- degree(graph, mode = "in") # Incoming links
degree_out <- degree(graph, mode = "out") # Outgoing links
degree_tot <- degree(graph, mode = "all") # Total links
# View top nodes by degree
head(sort(degree_in, decreasing = TRUE), 10) # Top 10 by in-degree
head(sort(degree_out, decreasing = TRUE), 10) # Top 10 by out-degree
head(sort(degree_tot, decreasing = TRUE), 10) # Top 10 by total degree
3. Plot Degree Distribution
To visualize how degrees are distributed:
# Histogram of degree distribution
hist(degree_tot, breaks = 30, col = "skyblue",
main = "Degree Distribution", xlab = "Degree", ylab = "Frequency")
# Alternatively, use a log-log plot (common in network science)
plot(degree_distribution(graph, mode = "all"),
log = "xy", type = "b",
main = "Log-Log Degree Distribution",
xlab = "Degree", ylab = "Proportion of Nodes")
4. Identify Hubs (Most Connected Nodes)
You can extract the most central nodes:
# Get top 5 nodes by in-degree
top_in <- names(sort(degree_in, decreasing = TRUE)[1:5])
# Get top 5 nodes by out-degree
top_out <- names(sort(degree_out, decreasing = TRUE)[1:5])
print(paste("Top in-degree nodes:", paste(top_in, collapse = ", ")))
print(paste("Top out-degree nodes:", paste(top_out, collapse = ", ")))
5. Visualize the Network (Optional)
If you want to visualize the network (works best for small to medium-sized graphs):
plot(graph,
vertex.size = 5,
vertex.label.cex = 0.7,
edge.arrow.size = 0.3,
layout = layout_with_fr) # Fruchterman-Reingold layout
6. Additional Metrics (Optional)
7. Exporting Results (Optional)
If you want to save the degree data for further analysis:
degree_data <- data.frame(
node = V(graph)$name,
in_degree = degree_in,
out_degree = degree_out,
total_degree = degree_tot
)
write.csv(degree_data, "node_degrees.csv", row.names = FALSE)
Summary
- Degree distribution helps identify hubs (highly connected nodes).
- In-degree shows which nodes are most "popular" (receiving many links).
- Out-degree shows which nodes are most "influential" (sending many links).
- Visualizations help understand network structure.
Would you like help with any specific part of this analysis?