[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Anybody ever use igraph to create regression path diagrams?

From: Tamás Nepusz
Subject: Re: [igraph] Anybody ever use igraph to create regression path diagrams?
Date: Tue, 17 Jul 2012 00:26:23 +0200

Dear Prof. Johnson,  

I'm not the developer of the R interface but I thought I'd answer anyway and 
let Gabor correct or extend what I say.

> 1. I need to have relatively complicated R objects that are
> represented by the igraph nodes. For example, a variable may be it
> 'ordinary' format X, or it may be log(x), or poly(x,d), or so forth.
> I'm thinking of still calling it X in the graph, but there would be
> some right-click magic to allow the user to ask for transformations.
> Is it feasible to add more variables inside a node object. Possible?
> Can you point me at the right starting point or example?

Internally, igraph treats the nodes as integers, but it allows you to attach 
arbitrary R objects as attributes to the nodes (and also to the edges). So, you 
can probably store all the extra information you need in an appropriately 
constructed R data type and then attach this to the node as a "data" attribute 
or something like that. For instance, suppose that you want to store the "type" 
of a node and the type is one of "ordinary", "log" or "exp". You can then do 
something like this:

V(g)$type <- "ordinary"          # assigns "ordinary" to the type of each node
V(g)[2]$type <- "exp"             # sets the type of node 2 to "exp"
V(g)$type                      # returns the types of each vertex

As for the right-click magic: tkplot does not allow the customization of the 
vertex popup menu yet, but it is probably not too difficult by taking the 
source code of tkplot() as a template, copying it, and then modifying it as 
needed (look for the lines starting with tkadd(vertex.popup.menu…)).  

> 2. Suppose a graph exists, and I view and re-arrange it with tkrplot.
> Is there a way to make the re-arranged objects take notice of the
> changes so that they are recorded permanently.

Again, this can be achieved by modifying the tkplot() function. tkplot() 
attaches event handlers to several mouse events of the drawing canvas; for 
instance, the line starting with tkitembind(canvas, tobind, "<B1-Motion>", …) 
attaches an event handler to the "<B1-Motion>" event, which is fired when the 
user moves the mouse while button 1 of the mouse is pressed. This corresponds 
to moving the selected vertices. Adding your own code into the body of the 
event handler function allows you to respond to the re-arrangement of the nodes.

Note that tkplot() does not support adding new vertices/edges or removing 
existing ones (as far as I know), so if the re-arrangements you wish to perform 
on the graphical representation of the models includes adding/removing vertices 
or edges, then this definitely needs more coding.

All the best,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]