Module 12 Assignment
For this assignment, I chose to use R Studio with ggnet2: network visualization with ggplot2, to create a visual social network analysis. Below is the code I created for it using the provided libraries and also the "igraph" library to generate a random graph and then using "ggnet2" to visualize it.
library(GGally)
library(network)
library(sna)
library(igraph)
library(ggplot2)
# Generate a random graph with 10 nodes and a 30% chance of an edge between nodes
g <- erdos.renyi.game(10, 0.3, type = "gnp")
# Convert the igraph object to a network object
net <- network::as.network.matrix(as_adjacency_matrix(g))
# Visualize the network
ggnet2(net, mode = "fruchtermanreingold", size = "degree", label = TRUE)
In this example, the mode parameter is set to "fruchtermanreingold", which means that the Fruchterman-Reingold algorithm is used for the layout of the network. The size parameter is set to "degree", which means that the size of the nodes is proportional to their degree (the number of edges connected to the node). The label parameter is set to TRUE, which means that the nodes are labeled with their IDs.
This creates the following visualization which changes each time it is ran as a random graph is generated.
Comments
Post a Comment