Exploring Social Network Visualization with R: Successes and Challenges
In the realm of data visualization, exploring social networks can yield fascinating insights into relationships and connectivity. Recently, I delved into this area using R, leveraging packages like GGally, network, sna, and ggplot2. Here’s a recount of my journey, highlighting both successes and challenges encountered along the way.
Package Installation and Setup:
The initial step was straightforward—installing and loading the necessary packages. Using install.packages() and library() commands, I quickly integrated GGally, network, sna, and ggplot2 into my R environment.
Generating Random Network Data:
I utilized the rgraph() function from the network package to create a random graph consisting of 10 nodes. Setting mode = "graph" and tprob = 0.5 ensured a symmetric and undirected graph.
Visualizing the Network:
With the network data prepared, I used ggnet2() from GGally to generate a visualization of the social network. This function creates an aesthetically pleasing graph representation.
CODE :
install.packages("GGally")
install.packages("network")
install.packages("sna")
install.packages("ggplot2")
library(GGally)
library(network)
library(sna)
library(ggplot2)
# Generate a random graph with 10 nodes and undirected edges
net <- rgraph(10, mode = "graph", tprob = 0.5)
# Create a network object from the random graph
net <- network(net, directed = FALSE)
# Assign vertex (node) names to the network
network.vertex.names(net) <- letters[1:10]
# Visualize the network using ggnet2
ggnet2(net)
ggnet2(net, node.size = 6, node.color = "black", edge.size = 1, edge.color = "grey")
Luckily I didn't run into any major failures, at first I tried to run the code but didn't have package "sna" installed but that was a quick fix.
Comments
Post a Comment