10
$\begingroup$

When I try to plot a 3-cycle, the edge direction is always counter-clockwise. The plotting code is

GraphPlot[{1 -> 0, 0 -> 2, 2 -> 1}, VertexLabeling -> True, 
 DirectedEdges -> True, PlotStyle -> {FontSize -> 13}, 
 VertexRenderingFunction -> ({EdgeForm[White], 
     RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.15], White, 
     Text[#2, #1]} &)]

and the output

enter image description here

I have tried many ways to change the edge direction without success. Anyone can help with this? Thank you!

$\endgroup$
8
$\begingroup$

You can use the option VertexCoordinateRules:

opts = {VertexLabeling -> True, DirectedEdges -> True, 
   VertexCoordinateRules -> {{0., 1.}, {1., 1.}, {.5, 0.}}, 
   PlotStyle -> {FontSize -> 13}, 
   VertexRenderingFunction -> ({EdgeForm[White], 
       RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.15], White, 
       Text[#2, #1]} &)};
GraphPlot[{1 -> 0, 0 -> 2, 2 -> 1}, opts]

Mathematica graphics

Or use Graph and give the vertices in the order you wish as the first argument:

opts2 = {VertexSize -> Medium,
   VertexStyle -> 
    Directive[EdgeForm[White], RGBColor[113/255, 190/255, 236/255]], 
   VertexLabels -> Placed["Name", Center], 
   VertexLabelStyle -> {Directive[White, FontSize -> 16]}, 
   VertexShapeFunction -> "Circle"};
Graph[{0, 1, 2}, {1 -> 0, 0 -> 2, 2 -> 1}, opts2]

Mathematica graphics

$\endgroup$
4
$\begingroup$

Simply as an alternative you can interactively rearrange the nodes, but to do so you must avoid VertexRenderingFunction. Here is an example:

postLabel[f_] := Text[Framed[n_, __], p_] :> f[p, n]

labelFn = {EdgeForm[White], RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.15], White, 
    Text[#2, #1]} &;

GraphPlot[{1 -> 0, 0 -> 2, 2 -> 1}, VertexLabeling -> True, DirectedEdges -> True, 
  PlotStyle -> {FontSize -> 13}] /. postLabel[labelFn]

You can then click as necessary to enter the graphic and select a node, then drag to rearrange as desired. Example result:

enter image description here

Reference: https://stackoverflow.com/a/8109449/618728

$\endgroup$
1
$\begingroup$

You can use Graph and set explicit VertexCoordinates.

g = CycleGraph[3,
  PlotTheme -> "CoolColor",
  VertexLabelStyle -> Directive[Large, White],
  VertexSize -> 0.3,
  VertexLabels -> Placed["Name", Center],
  DirectedEdges -> True
 ]

{Graph[g, VertexCoordinates -> CirclePoints[3]], 
 Graph[g, VertexCoordinates -> Reverse@CirclePoints[3]]}

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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