I’m looking to make a graph similar to this one:
Where not only do the vertices have different sizes according to their values, but the edges have different widths according to the values/force.
I have this data set here:
data = structure(c(NA, 0, 0, 0, 0.003122927, 0.00999241, 0.008685473,
0.007730365, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.003573423, 0, 0, 0,
0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.18893711, 0, 0, 0, NA, 0.183237263,
0.139293056, 0.120902907, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.132071652,
0, 0.457142857, 0.114500717, 0.322255215, 0, 0, 0, 0.097676062,
NA, 0.261095249, 0.131416203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.146191646,
0, 0, 0, 0, 0.086854728, 0, 0, 0, 0.023023646, 0.080959767, NA,
0.034786642, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.09469697,
0, 0, 0, 0.024480341, 0.049917782, 0.042613636, NA, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0.255554962, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.765625,
0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0,
0, 0.040201005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.041930937, 0, 0.192970073,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0.030562035,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0,
0, 0, 0, 0, 0, 0.151121606, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, NA, 0.039751553, 0, 0, 0, 0, 0, 0.026693325, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.011428571, NA), .Dim = c(23L,
23L), .Dimnames = list(c("sp1", "sp2", "sp3", "sp4", "sp5", "sp6",
"sp7", "sp8", "sp9", "sp10", "sp11", "sp12", "sp13", "sp14",
"sp15", "sp16", "sp17", "sp18", "sp19", "sp20", "sp21", "sp22",
"sp23"), c("sp1", "sp2", "sp3", "sp4", "sp5", "sp6", "sp7", "sp8",
"sp9", "sp10", "sp11", "sp12", "sp13", "sp14", "sp15", "sp16",
"sp17", "sp18", "sp19", "sp20", "sp21", "sp22", "sp23")))
This is my script:
library (igraph)
View (data)
class (data)
data= data.matrix(data, rownames.force = NA)
class (data)
graph <- graph_from_adjacency_matrix(data, mode = "directed", weighted = TRUE)
as_edgelist(graph, names=F)
as_adjacency_matrix(graph, attr="weight")
as_data_frame(graph, what="edges")
as_data_frame(graph, what="vertices")
graph = simplify(graph, edge.attr.comb=list(weight="sum","ignore"))
deg <- degree(graph, mode="all")
L <- layout_in_circle(graph)
plot(graph, edge.arrow.size=.1, vertex.color="black",vertex.size=deg*1.5,
vertex.frame.color="black", vertex.label.color="grey10", vertex.label.degree=-pi/6,
vertex.shape="circle",vertex.label.cex=1, vertex.label.dist=2,
vertex.label.font=1, edge.arrow.size=8, edge.width=0, edge.curved=0, edge.color="black",
edge.lty=1, layout=L)
This code above generated this graph:
Can someone help me? I’m really confused about that. I don’t have much experience with graphs in igraph. Thank you.