I have a network and want to plot it.
I use LayeredGraphPlot
, and the network is described as:
NetList={"A1" -> "a1", "A1" -> "b1", "b1" -> "A2", "a1" -> "a2", "A2" -> "b2",
"A2" -> "c2", "a2" -> "B3", "b2" -> "B3", "c2" -> "c3", "B3" -> "a3",
"B3" -> "b3", "a3" -> "A4", "b3" -> "A4", "c3" -> "c4", "A4" -> "a4",
"A4" -> "b4"};
LayeredGraphPlot[NetList, Bottom, VertexLabeling -> True]
Result:
I have two question:
1) Main question:
How can I tell LayeredGraphPlot
to put all a1, a2, a3, a4
in one vertical line, and b1, b2, b3, b4
in one line, and c2, c3, c4
in one vertical line? (the c
-elements are already in a vertical line coincidencely for this network).
2) Minor question:
If I only want to have labeling for certain elements (such as the upper-case Elements A1, A2, B3, A4
), how can I modify the LayeredGraphPlot-instruction?
Update
ad1) One methode to do this is VertexCoordinateRules
- i'm afraid it doesnt get much easier than that.
Update2
With the nice solution of hftf (below), the example above works perfectly. However, there is a problem with different networks.
When I have:
NetList={"A1" -> "a1", "A1" -> "b1", "b1" -> "A2", "a1" -> "a2", "A2" -> "b2",
"A2" -> "c2", "a2" -> "B3", "c2" -> "B3", "b2" -> "b3", "B3" -> "a3",
"B3" -> "c3", "a3" -> "A4", "c3" -> "A4", "b3" -> "b4", "A4" -> "a4",
"A4" -> "c4"};
GraphPlot[NetList, VertexLabeling -> True, VertexCoordinateRules -> coords,
DirectedEdges -> True]
I get the following:
The problem is, that b2
-> B3
and b3
-> A4
, even though there is no rule in NetList
for that. It happens because B3
and A4
are somehow in the way of b.
In the documentary of LayeredGraphPlot
, there are several examples how edges go around vertices that are in the way. But I could not get that work for my example. The error it tells me is
LayeredGraphPlot::vprmtd: Warning: the VertexCoordinateRules option with rule list value is only supported for the SpringElectricalEmbedding method. Switching to the SpringElectricalEmbedding method.
If I try using SpringElectricalEmbedding
, it complains about the VertexCoordinateRules
.
Is there a simple way around these hurdles? On solution would be to define the positions of As and Bs at some fractional position. But maybe there is some nicer way, where the edges go around the vertices in the way?