Reputation: 720
I'm using R to create a set of x,y coordinates to plot an organisation chart and am struggling to get a layout which is non-radial. I will use these coordinates to plot the graph in another application, hence the need for the coordinates not the plot.
My data is a 2 column data frame showing reporting relationshps with columns EmployeeID, ManagerID.
I am using package igraph and first create a graph using:
g<-graph.data.frame(dataframe)
Checking E(g)
I get the edges I would expect. Plotting the graph gives the correct structure in a radial form.
My understanding is that the reingold.tilford algorithm is the one I want to use to get a traditional non-radial tree. So I create a layout:
l<-layout.reingold.tilford(g)
This should have given me my x,y coordinates, however when I look at l I get something like:
[,1] [,2]
[1,] 0.000000e+00 3
[2,] 0.000000e+00 3
[3,] 0.000000e+00 1
[4,] 1.899762e-52 3
[5,] 1.224168e-17 3
[6,] 6.582031e-85 3
[7,] 5.626306e+175 3
plotting the graph again:
plot(g,l)
gives me a warning message:
In if (axes) { :
the condition has length > 1 and only the first element will be used
and the radial graph as before. Furthermore
summary(g)
gives:
IGRAPH DN-- 25 24 --
attr: name (v/c)
Upvotes: 2
Views: 1962
Reputation: 48061
Seems like a bug in the Reingold-Tilford algorithm implementation; at least the X coordinate in the 7th row of the layout is pretty weird. I would ask the same question on the igraph-help mailing list and also send a small example graph on which the authors can reproduce your issue.
Edit: after having examined the example graph you sent on the mailing list, it seems that 1) it is a bug in the Reingold-Tilford implementation, and 2) it can be worked around if you reverse all your edges so they point downwards in the tree (from parent to child) because this is what the Reingold-Tilford layout algorithm assumes, and it gives you erroneous results because it is not prepared for edges pointing in the "wrong" direction. Later versions of igraph will include a patch for the problem. Thanks for the heads up!
Edit 2: For the record, the above mentioned bug has been resolved and will be included in igraph 0.6.1. See the corresponding bug report for more information and the associated patch.
Upvotes: 2