Skip to main content
added 216 characters in body
Source Link
Szabolcs
  • 238.9k
  • 32
  • 653
  • 1.3k

It's explained on the doc page of GraphLayout. This documentation page is very long, and most of the information is under the Scope section, under specific layout methods.

Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}, GraphLayout -> {"LayeredEmbedding", "RootVertex" -> 1, "Orientation" -> Left}] 

Mathematica graphics

You do not need to use TreeGraph unless you also want to verify that the graph is indeed a tree. Graph will do. The key is GraphLayout.

With this layout, the root of directed trees is not detected automatically. You can specify it automatically as I did above. With "LayeredDigraphEmbedding", it is detected, but the layout will not be identical.


You can also achieve the same with IGLayoutReingoldTilford from the IGraph/M package.

IGLayoutReingoldTilford[ Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}], "RootVertices" -> {1}, "Rotation" -> Pi/2 ] 

Mathematica graphics

It's explained on the doc page of GraphLayout. This documentation page is very long, and most of the information is under the Scope section, under specific layout methods.

Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}, GraphLayout -> {"LayeredEmbedding", "RootVertex" -> 1, "Orientation" -> Left}] 

Mathematica graphics

You do not need to use TreeGraph unless you also want to verify that the graph is indeed a tree. Graph will do. The key is GraphLayout.


You can also achieve the same with IGLayoutReingoldTilford from the IGraph/M package.

IGLayoutReingoldTilford[ Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}], "RootVertices" -> {1}, "Rotation" -> Pi/2 ] 

Mathematica graphics

It's explained on the doc page of GraphLayout. This documentation page is very long, and most of the information is under the Scope section, under specific layout methods.

Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}, GraphLayout -> {"LayeredEmbedding", "RootVertex" -> 1, "Orientation" -> Left}] 

Mathematica graphics

You do not need to use TreeGraph unless you also want to verify that the graph is indeed a tree. Graph will do. The key is GraphLayout.

With this layout, the root of directed trees is not detected automatically. You can specify it automatically as I did above. With "LayeredDigraphEmbedding", it is detected, but the layout will not be identical.


You can also achieve the same with IGLayoutReingoldTilford from the IGraph/M package.

IGLayoutReingoldTilford[ Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}], "RootVertices" -> {1}, "Rotation" -> Pi/2 ] 

Mathematica graphics

Source Link
Szabolcs
  • 238.9k
  • 32
  • 653
  • 1.3k

It's explained on the doc page of GraphLayout. This documentation page is very long, and most of the information is under the Scope section, under specific layout methods.

Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}, GraphLayout -> {"LayeredEmbedding", "RootVertex" -> 1, "Orientation" -> Left}] 

Mathematica graphics

You do not need to use TreeGraph unless you also want to verify that the graph is indeed a tree. Graph will do. The key is GraphLayout.


You can also achieve the same with IGLayoutReingoldTilford from the IGraph/M package.

IGLayoutReingoldTilford[ Graph[{1 -> 2, 1 -> 3, 3 -> 4, 3 -> 5}], "RootVertices" -> {1}, "Rotation" -> Pi/2 ] 

Mathematica graphics