In my previous question, I wanted to plot a 2-dimensional MMA LayeredGraph[...]
on a 3-dimensional surface (or plane), and @KGLR answered the question in the context of the example given. With this new question, I like to go one step further and automize the code that @KGLR developed as a Mathematica function such as LayeredGraphPlot3D[...]
to simply plot the layered graph of LayeredGraphPlot[...]
in a 3-dimensional plane.
Given a layered graph:
ClearAll[edges];
edges = {1 -> 4, 1 -> 3, 1 -> 7, 1 -> 6, 4 -> 5, 5 -> 2, 3 -> 5,
5 -> 1, 2 -> 6, 6 -> 5, 2 -> 4, 2 -> 7};
LayeredGraphPlot[edges, VertexLabeling -> True,
EdgeRenderingFunction -> (Arrow[#1, 0.1] &)]
which produces:
I tried to mimic @KGLR's answer given below:
ClearAll[vertices, layers, vcoords]
vertices = {5, 3, 4, 7, 6, 1, 2};
layers = {1, 4, 2};
vcoords =
Thread[vertices ->
Join @@ MapThread[
Join[##, 2] &, {MapIndexed[CirclePoints[#2[[1]]/4, #] &,
layers], MapIndexed[ConstantArray[#2 - 1, #] &, layers]}]];
Show[Graphics3D[{Opacity[.1], EdgeForm[Gray], Lighting -> "Neutral",
Gray, InfinitePlane[{0, 0, #}, {{1, 0, 0}, {1, 1, 0}}] & /@
Range[0, 2]}, Boxed -> False],
Graph3D[edges, VertexCoordinates -> vcoords, VertexLabels -> "Name",
VertexStyle -> Black, VertexSize -> Tiny, ImageSize -> Medium],
PlotRange -> All, PlotRangePadding -> Scaled[.1],
EdgeShapeFunction -> (Arrow[#1, 0.1] &)]
which produces:
This 3-dimensional graph is mimicking the 2-dimensional layered graph above. However, my question is to create a Mathematica function such as LayeredGraphPlot3D[...]
to automatically convert a 2D layered graph into a 3D layered plane, a sample of which is shown above.
EdgeRenderingFunction
toEdgeShapeFunction
? $\endgroup$EdgeShapeFunction
works fine. Sorry that in my question it is understood as if you usedEdgeRenderingFunction
. I added that function and apparently it is my mistake. $\endgroup$EdgeShapeFunction
and the correct 3D-layered graph. $\endgroup$