2

Newbie here, so any help appreciated!

I have a weighted tree graph whose branches interest me. Can I use igraph to easily find branches (i.e. their edges and vertices) off a given path? Suppose I have a diameter path

E(mg, path = diam)

and branches off that path. Can I find branches, do stats with their weights, interrogate their associations with other things etc.?

Thanks a lot!

zo

Reproducible example:

library(igraph)

g <-erdos.renyi.game(50, 3/50)
mg <- minimum.spanning.tree(g)
diam <- get.diameter(mg)
E(mg)$color = "black"
E(mg, path = diam)$color = "purple"
E(mg, path = diam)$width = 6

So the question is: how do I extract the branches off the purple line within igraph? I'd like extract the branches off of the purple path and keep them in a data frame or some other object. Any thoughts?

  • 1
    It would be easier to help you if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with some sample input data and desired output. – MrFlick Nov 25 '15 at 04:31
  • I don't know if my editing of the original post alerts you to any change or my response to your response does, in any case I've tried to be more clear, sorry for not being so originally. Thanks – user1809593 Nov 25 '15 at 18:18
  • I don't understand. There are no weights in your example. You already have gotten the edges in order to color them with `E(mg, path = diam)`. So what exactly do you need that you can't get in this example? – MrFlick Nov 25 '15 at 18:25
  • Sorry, ignore the weights comment. What I want is a data frame or some other object which contains the branches coming off the purple diameter path. I can easily get the complement of the purple line, but I want the branches separately and I'm wondering if that's possible. – user1809593 Nov 25 '15 at 18:27

1 Answers1

1

If you want to get the set of edges that are incidental to the vertices along the purple line but bo not include the purple line, you can get use

EL <- difference( E(mg)[inc(diam)], E(mg, path = diam) )

We take the different between the all the edges that contain a point in diam and remove those edges that lie along diam. We can update the graph to make those edges blue

E(mg)[EL]$color<-"blue"
E(mg)[EL]$width<-6

plot(mg)

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Thank you kindly for your answer. How could I get all the rest of the edges along the branches and then distinguish the branches from each other? I.e., for the branch 1-32-24-7 I construct yellow edges, for the branch 23-19-18, I construct red edges, and so on exhaustively, and then I keep the red, yellow, etc. branches – user1809593 Nov 25 '15 at 18:45
  • I cannot find documentation on `from` or `to`, i.e. `E(mg)[ from(EL)]$color = "yellow"` should color branches yellow? – user1809593 Nov 27 '15 at 04:40
  • Let me add a possibly useful rephrasing of the question: how do I first find all the points not on purple path? How do I perform that set complement? – user1809593 Nov 29 '15 at 12:27
  • Comments are not the right place to add new important information to question or ask a new question. It would have been helpful to have this more explicit description in the original question. If you change the question from what you originally asked, you should just open a new question. – MrFlick Nov 29 '15 at 17:32
  • Thanks Mr. Flick, still learning how to use this. I posted a new question in http://stackoverflow.com/questions/33987043/finding-edge-sequences-and-nodes-of-branches-in-igraph – user1809593 Nov 29 '15 at 19:30