4
$\begingroup$

Hello, I am trying to make the diagonal edge (\mu N) horizontal and short in the following code corresponding to a flow chart:

vertices = vertices = {"S", "I", "D", "R"};
groups = {{"S"}, {"I"}, {"R", "D"}};
colors = Flatten@
   MapThread[Thread@*Rule, {groups, {White, Yellow, Red}}];
edges = {Style[Labeled["S" -> "I", \[Beta] "I"/\[Mu]  S/"N"], Red, 
    Thick], Style[Labeled["R" -> "S", Subscript[\[Gamma], r]], Brown, 
    Thick],
   Style[Labeled["I" -> "R", Subscript[\[Gamma], i]], Brown, Thick], 
   Style[Labeled["I" -> "S", \[Delta]], Brown, Thick]};

Then I added some invisible vertices to my flow chart as follows:

invisiblevertices = {"SS", "Rb", "Sb"};

newedges = {Style["S" -> "SS", Black, Thick], 
   Style["Sb" -> "S", Black, Thick], 
   Style["R" -> "Rb", Black, Thick], Style["I" -> "D", Black, Thick]};

newedgelabels = {Style[Subscript[\[Mu], s], Bold, Thick], 
   Style["\[Mu] N", Bold, Thick], 
   Style[Subscript[\[Mu], r], Bold, Thick], 
   Style[Subscript[\[Mu], i], Bold, Thick]};

edges2 = Join[edges, MapThread[Labeled, {newedges, newedgelabels}]];


options = {VertexLabels -> {_ -> Placed[Automatic, Center], 
     Alternatives @@ invisiblevertices -> None}, 
   VertexShapeFunction -> {"S" -> "Square", "R" -> "ConcaveHexagon", 
     "D" -> "ConcaveHexagon", 
     Alternatives @@ invisiblevertices -> None}, 
   VertexStyle -> colors, 
   VertexShapeFunction -> ({EdgeForm[Black], Disk[#1, 0.2], 
       Text[#2, #1]} &), VertexSize -> Large, ImageSize -> 450, 
   PerformanceGoal -> "Quality", 
   EdgeLabelStyle -> Directive[11, Background -> White]};

flow = LayeredGraphPlot[edges2, Bottom, options, 
  PlotStyle -> {"TemperatureMap", Bold}]

Thank you in advance.

$\endgroup$

1 Answer 1

7
$\begingroup$

1.

You can use a custom EdgeShapeFunction for the edge "Sb" -> "S":

LayeredGraphPlot[edges2, Bottom, options, 
 PlotStyle -> {"TemperatureMap", Bold}, 
 EdgeShapeFunction ->
   {("Sb" -> "S") -> (Arrow[{#[[2]] + {1, 0}, #[[2]]}, .15] &)}]

enter image description here

2.

Use the option VertexCoordinates and set the coordinates of "Sb" as desired:

vCoords = AssociationThread[
  VertexList @ edges2, 
  GraphEmbedding[edges2, {"LayeredDigraphEmbedding", "Orientation" -> Bottom}]];

LayeredGraphPlot[edges2, options, 
 PlotStyle -> {"TemperatureMap", Bold}, 
 VertexCoordinates -> {"Sb" -> vCoords["S"] + {1, 0}, v_ :> vCoords @ v}]

![enter image description here

$\endgroup$
2
  • $\begingroup$ Dear @kglr, thank you so much for your help! $\endgroup$ Dec 25, 2023 at 15:12
  • 1
    $\begingroup$ @RimADENANE, you are most welcome. $\endgroup$
    – kglr
    Dec 25, 2023 at 15:18

Your Answer

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

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