36

I am using graphviz to draw directed graphs . Now thing is that although I am able to generate graph correctly the graph is designed horizontally which is not according to my requirements . So, how can I draw directed graphs vertically Please help me with this

user2060673
  • 459
  • 1
  • 4
  • 8
  • 3
    What is your [rankdir](http://www.graphviz.org/doc/info/attrs.html#d:rankdir) setting? – Anders Lindahl Aug 06 '13 at 11:05
  • @Anders Lindahl I haven't dfined rankdir properties . please suggest me what modification I need to perform – user2060673 Aug 06 '13 at 11:17
  • 2
    Show an example of your graph description, and the command you use to render it. – Anders Lindahl Aug 06 '13 at 11:20
  • digraph G { graph [ bgcolor=lightgray, resolution=128, fontname=Arial, fontcolor=blue, fontsize=10 ]; node [ fontname=Arial, fontcolor=blue, fontsize=10]; edge [ fontname=Helvetica, fontcolor=red, fontsize=10 ]; "http://arunachaltourism.com/" -> "http://www.webcomindia.biz/profile.php"; "http://arunachaltourism.com/#" -> "http://arunachaltourism.com/"; "http://arunachaltourism.com/aalo.php" -> "http://arunachaltourism.com/";} – user2060673 Aug 06 '13 at 11:31

3 Answers3

27

Given the following script, which I've extracted from the comments to the question and edited to make it run successfully by removing some extraneous semicolons:

digraph G { 
    graph [ bgcolor=lightgray, resolution=128, fontname=Arial, fontcolor=blue, fontsize=10 ]; 
    node [ fontname=Arial, fontcolor=blue, fontsize=10]; 
    edge [ fontname=Helvetica, fontcolor=red, fontsize=10 ]; 
    "arunachaltourism.com/" -> "webcomindia.biz/profile.php"; 
    "arunachaltourism.com/#" -> "arunachaltourism.com/";
    "arunachaltourism.com/aalo.php" -> "arunachaltourism.com/";
} 

I called the script x.dot. Now, running:

dot x.dot -Tjpg -o x.jpg

... produces:

enter image description here

... because the default is rankdir=TB. Inserting:

rankdir=LR

... as the second line of the script and running the script through dot again gives:

enter image description here

Thus, it isn't clear to me why the graph might have been drawn horizontally the first time, but you will be able to see how using rankdir can make the graph come out either horizontally or vertically.

Simon
  • 10,679
  • 1
  • 30
  • 44
23

(old question, but why not!)

You can as well run:

dot -Grankdir=LR -Tpng myfile.dot -ogeneratedpng.png
purnank
  • 526
  • 3
  • 2
7

You can use rankdir as a property in the dot file:

digraph G {
     rankdir=LR;  //left to right
     //B bottom  T top  L left R right
      start->a1;
      a1 -> b3;
      b2 -> a3;
      a3 -> a0;
      a3 -> end;
      b3 -> end;
    }

The script generate the following graph from left to right:

You can try the script online enter image description here

M.Hassan
  • 10,282
  • 5
  • 65
  • 84