I would like to draw a Graph
with defined $x$ coordinates and variable node sizes. If I simply replace the $x$ coordinates of a graph, then nodes can overlap and edges may cross each other. I would appreciate any help pointing me in the right direction on how to go about setting the $Y$ coordinates, or alternative approaches to plotting, such that the nodes are nicely spaced out and, as far as possible, edges don't cross.
(*egdata*)
relationships =
{1 <-> 2, 2 <-> 3, 2 <-> 4, 2 <-> 6, 3 <-> 5, 6 <-> 7,4 <-> 8, 4 <-> 9};
numNodes =
Max[relationships[[All, 2]]];
sizes = RandomReal[{0.25, 1}, numNodes];
xCoords = {0, 1, 2, 2, 3, 3, 4, 5, 5};
I would like to be able to automatically generate a plot similar to this (without having to manually specify $Y$ coordinates.):
Graph[
relationships, VertexSize -> Thread[Range[numNodes] -> sizes],
VertexCoordinates ->
Transpose[{xCoords,(*yCoords*){1, 1, 1, 3, 2, 1, 2, 3, 4}}]]
Using VertexCoordinateRules
with GraphPlot
is the best I can do, but doesn't solve the problem:
relationships =
{1 -> 2, 2 -> 3, 2 -> 4, 2 -> 6, 3 -> 5, 6 -> 7, 4 -> 8, 4 -> 9};
xCoords =
{0, 1, 2, 2, 3, 3, 4, 5, 5};
numNodes =
Max[relationships[[All, 2]]];
sizes = RandomReal[{0.25, 1}, numNodes];
GraphPlot[
relationships,
VertexCoordinateRules ->
Thread[
Range[numNodes] ->
Transpose[{xCoords, Table[Automatic, {numNodes}]}]],
VertexRenderingFunction -> ({White, EdgeForm[Black], Disk[#, .3],
Black, Text[#2, #1]} &)
]
Thanks in advance!
TreePlot[relationships, Left]
looks like it may be useful to you. $\endgroup$