wk12

 

wk12.R

assas

2023-03-28

# Load required libraries
library(GGally)

## Warning: package 'GGally' was built under R version 4.2.3

## Loading required package: ggplot2

## Warning: package 'ggplot2' was built under R version 4.2.3

## Registered S3 method overwritten by 'GGally':
##   method from  
##   +.gg   ggplot2

library(network)

library(sna)

library(ggplot2)

# Create a random graph with 10 nodes
net
<- rgraph(10, mode = "graph", tprob = 0.5)

# Convert the graph to a network object
net
<- network(net, directed = FALSE)

# Create custom labels for the vertices
vertex_labels
<- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")

# Customize the network visualization
ggnet2_customized
<- ggnet2(net,
                           
node.size = 6,
                           
node.color = "black",
                           
edge.size = 1,
                           
edge.color = "grey",
                           
label = vertex_labels,
                           
label.size = 4,
                           
label.color = "blue",
                           
label.offset = 0.5)

# Display the customized network visualization
print(ggnet2_customized)


One of the issues I faced was finding the right aesthetic arguments for the ggnet2 function to make the graph look more presentable. But I got to learn another new library available for data visualization. 

Comments