Edge-list Network graph R

430 views Asked by At

I am stuck in drawing a graph on R. In particular, I would like to make a network graph as this one

but with the central node of another color and the size of the other nodes as big as the column weights in the dataset. The dataset is the following:

structure(list(owner = c("MASTERS", "MASTERS", "MASTERS", "MASTERS", "MASTERS", "MASTERS","MASTERS", "MASTERS"), 
armed_band = c("Biakatu Communal Militia", "FPJC", "FRPI", "LRA", "Mayi Mayi Militia", "Mayi Mayi Militia (Safisha Mabaya)", "Mayi Mayi Militia (Simba)", "RCD"), 
weigth = c(1, 1, 1, 5, 2, 1, 1, 1)), 
row.names = c(NA, -8L), 
class = c("tbl_df", "tbl", "data.frame")) 

The code I am using at the moment is the following:

aux_samearea_network <- read_excel("file") 
concessions_network = network(aux_samearea_network, 
                     matrix.type = "edgelist", 
                     ignore.eval = FALSE,
                     names.eval = "weights" ) 

concessions_network %v% "Concession" = ifelse(
aux_samearea_network$armed_band %in% c("LRA",
"Mayi Mayi Militia", 
"Biakatu Communal Militia",
"FPJC",
"FRPI",
"Mayi Mayi Militia (Safisha Mabaya)",
"Mayi Mayi Militia (Simba)",
"RCD"), "Armed Band", "Concession")

ggnet2(concessions_network, 
   node.size = "weights", 
   node.color = "lightblue", 
   edge.size = 1, 
   edge.color = "grey",
   main = "Network concession MASTERS",
   edge.label = "weights",
   label = TRUE,)

Can anyone help me with this please? I would be extremely grateful.

1

There are 1 answers

0
ThomasIsCoding On

I guess you can try igraph like below

library(igraph)
g <- graph_from_data_frame(aux_samearea_network)
V(g)$color <- factor(V(g)$name %in% aux_samearea_network$owner)
plot(g,
  edge.width = aux_samearea_network$weigth,
  edge.label = aux_samearea_network$weigth
)

and we will get enter image description here