Keon-Woong Moon
Keon-Woong Moon

Reputation: 226

GraphViz - How to have a subgraph be top-to-bottom when main graph is left-to-right?

I have a graph in direction of LR

digraph {
  rankdir=LR;
  node [shape=box]
  x1;x2;x3;y1;y2;y3;y4;y5;y6;y7;y8;
  node [shape=oval]
  ind60;dem60;dem65;
  {x1,x2,x3} -> ind60 
  dem65->{y5,y6,y7,y8} 

  subgraph cluster_0{
  rankdir=TB 

  {y1,y2,y3,y4} -> dem60[constraint=false]

  }
  ind60->dem60 ind60->dem65 dem60->dem65
}

The result is as follows: image1

I want the subgraph in TB direction. How can I achieve this?

subgraph

Upvotes: 1

Views: 3199

Answers (1)

Jens
Jens

Reputation: 2617

According to documentation rankdir only works for graphs not for subgraphs.

You can workaround this by adding some scaffolding in form of invisible edges and nodes like this

digraph {
  rankdir=LR;
  node [shape=box]
  x1;x2;x3;y1;y2;y3;y4;y5;y6;y7;y8;
  node [shape=oval]
  ind60;dem60;dem65;
  {x1,x2,x3} -> ind60 
  dem65->{y5,y6,y7,y8} 

  subgraph cluster_0{

      y2a[shape=point color=none]
      y1->y2->y2a->y3->y4[color=none weight=1000]
      {y1 y2}->dem60
      {rank=same y2a->dem60[color=none]}
      {y3 y4}->dem60

  }
  {rank=same ya[shape=point color=none] x1 x2 x3}
  {rank=same yb[shape=point color=none] y5 y6 y7 y8}
  ya->y1[color=none] y4->yb[color=none]
  ind60->dem60 ind60->dem65 dem60->dem65
}

enter image description here

Upvotes: 1

Related Questions