After thinking about this a little, it occurred to me that this could be tricky and that someone had probably already done this, since networks are an area of pretty heavy application in R
. In package igraph
I found an approach that will work if you can get your edge list reformatted slightly. Here is an example using made up data:
library("igraph")
set.seed(11)
ed <- sample(1:10, 30, replace = TRUE)
g <- graph(edges = ed)
str(g)
plot(g)
m <- is.mutual(g)
The T/F vector in m
can then be used to color your edges as desired.
Note that in this example an edge starting and ending on the same node/vertex and duplicated edges are counted as "mutual" by the function. If you have those as well as reciprocal edges you might have to do some additional fiddling. This example has one reciprocal edge (1 <-> 3).