1

I'm making a directed network in R studio with the igraph package. I would like to display two edges between nodes where applicable, both weighted, one for ins and one for outs. I'm very new to R and managed to get weighted edges that compile both ins and outs but would like them separated.

I've googled my problem with no avail, it might be from phrasing it wrong. I apologize in advance if I worded it badly.

EDIT: Minimal reproducible sample:

OPR.df <- data.frame("From" = c(c("8", "8", "8", "8", "7", "25", "24", "1A", "12", "12"),
                                c("12", "12", "12", "17", "17", "17"),
                                c("17", "17", "17", "17"),
                                c("17", "17", "17", "17", "17", "9A", "9", "17", "9", "17", "9"),
                                c("9", "17", "17", "17")),
                     "To" = c(c("8", "8", "8", "7", "25", "24", "1A", "12", "12", "12"), 
                              c("12", "12", "17", "17", "17", "17"),
                              c("17", "17", "17", "17"),
                              c("17", "17", "17", "17", "9A", "9", "17", "9", "17", "9", "17"),
                              c("17", "17", "17", "17")))


opr.d <- graph_from_data_frame(d = OPR.df,  
                             directed = T)

# I think this is the part where I set this??
E(opr.d)$weight <- 1

opr.sd <- simplify(opr.d,
            remove.multiple = T,
            remove.loops = F,
            edge.attr.comb = c(weight = "sum",
                               type = "ignore"))
E(opr.sd)$width <- E(opr.sd)$weight/3

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 27 '20 at 00:14
  • Sorry, I just added one now! – user13822027 Jun 27 '20 at 01:10

1 Answers1

0

There are a number of things that you can do to make the two-way links more visible. First, plotting using the default layout crowds the vertices 9, 9A and 17 too close together. There is no room to see the edges. I will use layout_with_graphopt , which works fine for this example, although for more complex examples you may need to tune up the layout even more.

set.seed(4321)
plot(opr.sd, xpd=NA)
set.seed(4321)
plot(opr.sd, layout=layout_with_graphopt)

Plots with default layout and with graphopt

Of course, we still have the problem from your original question: the arrows overlap each other. You can fix this using the edge.curved argument. I wanted all of the arrows to be straight except where they overlap, so I created a customized curvature vector to adjust only the overlapping edges. Also, the arrow heads are too big and made it hard to see the arrows, so I made the heads a bit smaller. All together, we get:

CURV = rep(0,ecount(opr.sd))
CURV[2]  = 0.6
CURV[11] = 0.6
CURV[13] = 0.6

set.seed(4321)
plot(opr.sd, layout=layout_with_graphopt, 
    edge.arrow.size=0.7, edge.curved=CURV, frame=T)

Graph with some curved edges

You might still want to tweak this a bit, but I think this shows the path to solving your problem.

G5W
  • 36,531
  • 10
  • 47
  • 80