2
$\begingroup$

I want to have three network types. My plan is to put them together in a figure file via marking them with (a) (b) and (c). The figures that I want to have, have some problems. Here is my code

Graph[{2 -> 1, 3 -> 2, 4 -> 3, 5 -> 4}, EdgeStyle -> Arrowheads[.04], VertexLabels -> Placed["Name", Center], VertexSize -> 0.5, ImagePadding -> 20, VertexStyle -> White, EdgeStyle -> Directive[Blue], VertexShapeFunction -> "Square"]

enter image description here

Graph[{1 \[DirectedEdge] 2, 1 \[DirectedEdge] 3, 2 -> 4, 2 -> 5}, EdgeStyle -> Arrowheads[.04], VertexLabels -> Placed["Name", Center], VertexSize -> 0.2, VertexStyle -> White, EdgeStyle -> Blue, VertexShapeFunction -> "Square"]

enter image description here

Graph[{1 \[DirectedEdge] 2, 1 \[DirectedEdge] 3, 1 -> 4, 1 -> 5}, EdgeStyle -> Arrowheads[.04], VertexLabels -> Placed["Name", Center], VertexSize -> 0.35, VertexStyle -> White, EdgeStyle -> Blue, VertexShapeFunction -> "Square"]

enter image description here

The first graph is a example of a tandem graph, the second is a tree and the last one is a parallel. The problems are as follows:

  1. I want to put all three figures side by side, therefore the first serial one needs to be vertical not horizontal. The direction of the arrows is correct in the figure.

  2. For all graphs, the names of the square boxes need to be $S_1$, $S_2$... intead of only numbers.

  3. The length of the edges must be the same. For example second figure has very long edges compared to others

  4. The Tree (second) and the parallel (third) networks should have reversed directed edges. The central node should always be $S_1$ and the arrows need to direct that node.

  5. The size of the squares need to comparable. I was roughly able to do this.

  6. Every node (except node number 1) needs to have a label $y_i$ on the square, where $i$ is the number of the node

  7. Every edge needs to be labeled with $u_i$ where $i$ is the number of the outgoing edge. The edge labels should not touch the edges, e.g. can be to the left of the edges.

  8. Edges can have all blue colors or black colors. I fail to change the color of the edges. The current color is blue like, not a real blue for example.

  9. Node number 1 must be in red color for all graphs.

Thanks in advance for your help.

$\endgroup$
3
  • 1
    $\begingroup$ You should be able to find solutions to all of your problems by consulting the documentation. See GraphicsGrid,VertexCoordinates, EdgeStyle, etc... $\endgroup$
    – DavidC
    Mar 7, 2015 at 13:45
  • $\begingroup$ @DavidCarraher thanks I will check. Edgestyle, I already tried and it didnt work. Blue is still blue as in the figures for example. Black also didnt work. $\endgroup$ Mar 7, 2015 at 13:48
  • $\begingroup$ Maybe this can help also. $\endgroup$
    – SquareOne
    Mar 7, 2015 at 14:47

1 Answer 1

3
$\begingroup$
vlabels = Join[{1 -> Placed[Style[Subscript["S", ToString@1], 18], Center]}, 
                # -> Placed[{Style[Subscript["S", ToString@#], 18], 
                      Style[Subscript["y", ToString@#], 14]}, {Center, Above}] & /@ Range[2, 5]];

elF = Property[#, {EdgeStyle -> Directive[Opacity[1], Arrowheads[Large],Blue], 
    EdgeLabels -> Placed[Style[Subscript["u", ToString@#[[1]]], 14], {1/2, {2, 1}}]}] &;
el1 = elF /@ {2 -> 1, 3 -> 2, 4 -> 3, 5 -> 4};
el2 = elF /@ (Reverse /@ {1 -> 2, 1 -> 3,  2 -> 4, 2 -> 5});
el3 = elF /@ (Reverse /@ {1 -> 2, 1 -> 3,  1 -> 4, 1 -> 5});

style = { VertexLabels -> vlabels, VertexSize -> {"Scaled", .1}, ImagePadding -> 30, 
  VertexStyle -> {1 -> Red, ## & @@ Thread[Range[2, 5] -> White]},
  VertexShapeFunction -> "Square",
  GraphLayout -> {"LayeredEmbedding", "RootVertex" -> 1,
                   LayerSizeFunction -> (2 &), "LeafDistance" -> 2}};

With these settings we address almost all of the eight requirements. Adjusting the image sizes manually we get:

g1 = Graph[el1,  style /. Above -> After, ImageSize -> {200, 400}];
{g2, g3} = Graph[#, style, ImageSize -> #2] & @@@ {{el2, {400, 400}}, {el3, {500, 500}}};
Row[{g1, g2, g3}]

enter image description here

$\endgroup$
8
  • $\begingroup$ Thank you very much. Please let me check. The first one: head side top, the arrows need to look up then, and $y_i$ on top of squares. Is it possible? $\endgroup$ Mar 7, 2015 at 14:59
  • $\begingroup$ @Seyhmus, re "head side top" and "$y_i$ on top of squares", does the updated version address these? $\endgroup$
    – kglr
    Mar 7, 2015 at 15:23
  • $\begingroup$ Almost. For the first one: $S_1$ on top with red, the order will change and for all figures $u_{i->j}$ could be only $u_i$ but your version also seems nice and last point to be consistent with all figures, $y_i$ to the left of the squares. This is correct for figure $2$ and $3$ and I think then all $u_i$ could be to the right of the edges in all figures. Then everything would be perfect. $\endgroup$ Mar 7, 2015 at 15:32
  • $\begingroup$ $u_i$ to the left are okay. Sorry for that only for the first figure $y_i$ need to be to the righ then fine. $\endgroup$ Mar 7, 2015 at 15:38
  • $\begingroup$ now all perject. The last question. I guess it seems difficult to put $y_i$ on top a bit right, right? $\endgroup$ Mar 7, 2015 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.