Mathematica Asked on March 15, 2021
I’ve produced the following tree plot:
But I want the root to be $a$, which is a string. I looked at the documentation, it says:
So it seems it’s very easy, we just write something like:
TreePlot[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, 3 -> 8, 4 -> 5, 7 -> 8}, Automatic, 1, VertexLabels -> Automatic]
Where we switch 1
by "a"
but this is not working. So how do I reference a string as the root node of a graph?
edgelist = {"a" -> "d", "a" -> "f", "a" -> "h", "b" -> "f", "c" -> "h",
"d" -> "e", "g" -> "h"};
TreePlot[edgelist, Automatic, "a", VertexLabels -> Automatic]
TreePlot[edgelist, Automatic, "e", VertexLabels -> Automatic]
If the vertex list of your tree is Range[8]
:
edgelist2 = {1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, 3 -> 8, 4 -> 5, 7 -> 8};
TreePlot[edgelist2, Automatic, 1, VertexLabels -> Automatic]
you can label the vertices using vlabels
:
vlabels = CharacterRange["a", "h"];
TreePlot[edgelist2, Automatic, 1, VertexLabels -> {i_ :> vlabels[[i]]}]
Answered by kglr on March 15, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP