How to put the parent node higher than the children nodes in a drawing for a graph?
You can use
Graph
with the optionGraphLayout -> "LayeredDigraphEmbedding"
, orLayeredGraphPlot
, orTreePlot
specifying the root vertex in the third argument.
Graph[{7 -> 2, 2 -> 3, 3 -> 4, 3 -> 5},
VertexLabels -> "Name",
GraphLayout->"LayeredDigraphEmbedding"]
LayeredGraphPlot[{7 -> 2, 2 -> 3, 3 -> 4, 3 -> 5},
VertexLabels -> "Name"]
same picture
TreePlot[{7 -> 2, 2 -> 3, 3 -> 4, 3 -> 5}, Automatic, 7,
VertexLabels-> "Name", DirectedEdges -> True]
Note: LayeredGraphPlot
and TreePlot
produce Graphics
objects.
Graph[{7 -> 2, 2 -> 3, 3 -> 4, 3 -> 5}, VertexLabels -> "Name",
GraphLayout -> {"LayeredEmbedding", "RootVertex" -> 7}]