I try to plot a bipartite network with the edges of the same color than one of their nodes.
For example, let's take an movie/actor bipartite graph as an exemple, with 7 movies and 15 actors, and each actor has a nationality.
I want to have the edge between an actor and a movie of the same color than the nationality of the actor.
NG1 <- 7
NG2 <- 15
Nat <- sample(x = c("French", "English", "Italian", "American", "Chinese"), size = NG2, replace = T)
G <- graph.empty(NG1+NG2)
[Here, head(Nat)
returns "Italian" "English" "American" "French" "French" "French"
]
The code to create the edgelist:
E1 <- sample(x=1:NG1, size = 30, replace = T)
E2 <- sample(x=(NG1+1):(NG1+NG2), size = 30, replace = T)
EL <- c(rbind(E1, E2))
G <- add_edges(G, EL, nat = Nat[E2-NG1])
[Here, head(EL)
returns 1 14 3 13 2 15
]
The different aes arguments:
GROUP <- c(rep("Movie", NG1), rep("Act", NG2))
COL <- c(rep("Movie", NG1), Nat)
TXT <- c(as.character(1:NG1), letters[1:NG2])
And now the ggraph instructions:
ggraph(G, layout = 'kk') +
geom_node_point(aes(col = COL, shape = GROUP, size = 7)) +
geom_edge_link(aes(col = nat)) +
geom_node_text(aes(label = TXT), size = 4)
As you can see in the bottom, actor a, which is Italien has a blue node, but is connected with a pink edge with movie 7... How can I specify the color palette for nodes (here 6 colors) and edges (the 5 first colors of the nodes)?
I hope that I have made clear.