-1

Got a question for you about the package igraph. When the igraph is directed, is it possible to give an input like from A to C over B? A directed edge from A to C over B?

Like a train from Spain(A) to Russia(C). The Train drives through Switzerland(B) but it doesn't stop there.

How can I do something like this?

Thank you guys

meilirog
  • 15
  • 1
  • 4
  • I think the best way to do this would be to set an edge attribute e.g. `E(g)$MakeStop` and set to TRUE/FALSE and connect all nodes in which a train passes through the city – emilliman5 Mar 14 '18 at 18:15
  • Thanks for the Hint! Can you please make a little example? – meilirog Mar 14 '18 at 21:38
  • Why don't you provide some example data and then I can work up a solution. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – emilliman5 Mar 14 '18 at 23:43
  • Would you be satisfied with creating 3 edges out of one? Make two pass through edges (A-B and B-C), then make a connection edge (A-C). – adm Mar 15 '18 at 16:17
  • 2
    Possible duplicate of [merging two igraph in r](https://stackoverflow.com/questions/49279686/merging-two-igraph-in-r) – emilliman5 Mar 19 '18 at 17:47

1 Answers1

0

It depends on how you're storing your data. If you have information stored in edges, then this might work:

g <- make_empty_graph() + 
  vertices(c('a', 'b', 'c')) +
  edges(c('a', 'b',
          'b', 'c',
          'a', 'c',
          'a', 'b',
          'b', 'c'),
        train = c("local_1",
                  "local_1", 
                  "express_2",
                  "local_2",
                  "local_3"))

leg_1 <- E(g)[["a" %->% "b"]]
leg_2 <- E(g)[["b" %->% "c"]]

train_of_interest <- leg_1$train[leg_1$train %in% leg_2$train]
struggles
  • 825
  • 5
  • 10