A sample of my data set is as follows. I wrote the following code for network visualisation. My graph is made of an Adjacency matrix with a child and parent column. The label column has 3 levels as 0, 1, 2. I put labels as a vertex and edge attribute. The problem in the produced plot is, the colour of the parent node and the edge from it, should be the same because they follow the same rules, but in some case, it is not. why they are different?
the data :
row row child name child parent parent name vaccine label
40 39 MaryJoNabuurs 1.392302e+18 1.392218e+18 TweeetLorraine
AstraZeneca 2
41 40 ElizabethDuncan 1.392297e+18 1.392218e+18 TweeetLorraine AstraZeneca 2
42 41 7Rose75 1.392294e+18 1.392218e+18 TweeetLorraine AstraZeneca 1
43 42 wh0careswh0 1.392336e+18 1.392294e+18 7Rose75 AstraZeneca 0
44 43 T_ProudVeteran 1.392330e+18 1.392294e+18 7Rose75 AstraZeneca 2
45 44 TweeetLorraine 1.392294e+18 1.392294e+18 7Rose75 AstraZeneca 2
46 45 Norlaine 1.392288e+18 1.392218e+18 TweeetLorraine AstraZeneca 2
47 46 elham95264575 1.393212e+18 1.392288e+18 Norlaine AstraZeneca 1
48 47 soyfreemike 1.392387e+18 1.392288e+18 Norlaine AstraZeneca 0
49 48 KMTCarr 1.392288e+18 1.392218e+18 TweeetLorraine AstraZeneca 2
50 49 angela_petta 1.392283e+18 1.392218e+18 TweeetLorraine AstraZeneca 2
51 50 lhoneyimhome 1.392272e+18 1.392218e+18 TweeetLorraine AstraZeneca 2
net1 <- graph_from_data_frame(df %>% select("child","parent"))
rel = get.adjacency(net1, sparse = FALSE)
graph = graph_from_adjacency_matrix(rel, mode="directed",weighted = TRUE)
graph = simplify(graph, remove.loops=TRUE)
graph
summary(graph)
vertex_attr(graph, "label") <- df$label
#Set edge attribute:
edge_attr(graph, "label") <- df$label
E(graph)$color[E(graph)$label == 2] <- '#B3DE69' #green
E(graph)$color[E(graph)$label == 1] <- '#80B1D3' #yellow
E(graph)$color[E(graph)$label == 0] <- '#FB8072'#purple
V(graph)$color[V(graph)$label == 2] <- '#B3DE69'
V(graph)$color[V(graph)$label == 1] <- '#80B1D3'
V(graph)$color[V(graph)$label == 0] <- '#FB8072'
g<-c('#B3DE69','#80B1D3','#FB8072')
plot(graph,layout=layout.fruchterman.reingold,
vertex.frame.color=NA,vertex.label.color="black",
edge.label = NA,
vertex.size=3, usecurve=TRUE,
edge.lwd=0.02,
vertex.dist=10,vertex.label.dist=2,vertex.label.cex=0.9,
pad=0.9,alpha=80,
edge.arrow.size=.1)
legend("bottomleft",legend= c("Positive","Neutral","Negative"),
col=g,pch=19,pt.cex=1.5,bty="n",
title="Label category")
title(main="Visualization ", cex.main=1)
UPDATED:
I figured out the problem is using simplify. when I remove it, I get the correct plot. the problem is I don't want loop in my graph, what should I do instead of using simplify?