I’m working on a Markov Chain and hope there is a way to impose control over how Mathematica places edges to connect vertices in a Graph
. My Markov Chain currently consists of 4 vertices with 2 of the edges crossing and is shown below. The edge coming out of Vertex 4 labeled m
and connecting to Vertex 1 is what I’d like to change.
Rather than being orientated as a vertical straight line, is it possible to direct this edge from Vertex 4 to the right in an arc so that the arc passes to the right of the k
and then connects to Vertex 1 ? This will remove the crossing, be easier for others to read and be more architecturally correct.
My code is below. Thanks for any help.
softwareapplication =
DiscreteMarkovProcess[
1, {{0, b, c, 0}, {e, f, g, h}, {i, 0, k, l}, {m, n, o, 0}}];
transitionmatrix =
MarkovProcessProperties[softwareapplication, "TransitionMatrix"] //
MatrixForm
vertexlabels = {1 -> Placed["1", Center], 2 -> Placed["2", Center],
3 -> Placed["3", Center], 4 -> Placed["4", Center]};
edgelabels = {
1 \[DirectedEdge] 2 -> transitionmatrix[[1, 1, 2]],
1 \[DirectedEdge] 3 -> transitionmatrix[[1, 1, 3]],
2 \[DirectedEdge] 1 -> transitionmatrix[[1, 2, 1]],
2 \[DirectedEdge] 2 -> transitionmatrix[[1, 2, 2]],
2 \[DirectedEdge] 3 -> Placed[transitionmatrix[[1, 2, 3]], .25],
2 \[DirectedEdge] 4 -> transitionmatrix[[1, 2, 4]],
3 \[DirectedEdge] 1 -> transitionmatrix[[1, 3, 1]],
3 \[DirectedEdge] 3 -> transitionmatrix[[1, 3, 3]],
3 \[DirectedEdge] 4 -> transitionmatrix[[1, 3, 4]],
4 \[DirectedEdge] 1 -> Placed[transitionmatrix[[1, 4, 1]], .25],
4 \[DirectedEdge] 2 -> transitionmatrix[[1, 4, 2]],
4 \[DirectedEdge] 3 -> transitionmatrix[[1, 4, 3]]
};
Graph[softwareapplication, VertexLabels -> vertexlabels,
EdgeLabels -> edgelabels, VertexSize -> Small, ImageSize -> Medium,
VertexCoordinates -> {{0, 2}, {-1, 1}, {1, 1}, {0, 0}}]
Graph
-related functionality.GrapLayout -> "PlanarEmbedding"
will plot with no edge crossings, but you can't specify your vertex coordinates, so it's probably not useful for you. There's the "EdgeLayout" option but it doesn't seem to have anything that will automatically create a crossing-free edge layout, given some vertex coordinates. To sum up: it's probably difficult to do this automatically using Mathematica. $\endgroup$