0

I am using diagrammer for a diagram that should look like the one below but without any success. enter image description here

I have tried the following code

library(DiagrammeR)
grViz("
digraph boxes_and_circles {

  graph [layout = circo,
      overlap =T,
      outputorder = edgesfirst,
      bgcolor='white',
      splines=line]#controls l type setup
      edge[labelfontname='Arial',fontSize=13,color='red',fontcolor='navy']
      node [shape = box,style='filled',
      fillcolor='indianred4',width=2.5,
      fontSize=20,fontcolor='snow',
      fontname='Arial']
  a;b;c;d;e

  node [shape = square,
        fixedsize = true,
        width = 0.9] // sets as circles
  # several 'edge' statements
  a->b;a->c;a->d;a->e;c->b;d->b;e->b}")

Which gives me the following diagram enter image description here

Any thought on how to tweak the code to get the desired output? Any help would be highly appreciated. Thank you.

DSTO
  • 265
  • 1
  • 9
  • Are you tied to the diagrammeR language? Is this a "one-time-only" diagram, or do expect on creating many variations? – sroush Mar 07 '23 at 20:39
  • Thanks. I expect to create many variations. Happy to use r package other than diagrammer. – DSTO Mar 07 '23 at 20:41

1 Answers1

1

Hmm

  • the circo layout engine doesn't seem to apply here, changed to dot
  • added aPrime & bPrime nodes for desired result
  • used rank= to start ranking
  • used invisible edges to set ranking for lower nodes
  • added port specification to some edges
  • used group attribute for vertical alignment

For more info on these attributes see: https://www.graphviz.org/pdf/dotguide.pdf and: https://www.graphviz.org/doc/info/attrs.html

digraph boxes_and_circles {

  graph [layout = dot  // not circo
      overlap =false,  // not "T"
      outputorder = edgesfirst,
      bgcolor="white",
      splines=line  //polyline
      nodesep="2.0"
      ]#controls l type setup
      edge[labelfontname="Arial",fontSize=13,color="red",fontcolor="navy"
      ]
      
      node [shape = box,style="filled",
      fillcolor="indianred4",width=2.5,
      fontSize=20,fontcolor="snow",
      fontname="Arial"
      ]
  {rank=min  a [group=g1] ;b [group=g2]}
  {rank=same
    aPrime [label="A on C D E" group=g1]
    bPrime [label="C D E on B" group=g2]
    }
    {
      edge[style=invis]
      c-> d-> e
   }

  // what is the new node definition for ??
  node [shape = square,
        fixedsize = true,
        width = 0.9] // sets as circles
  # several "edge" statements
  a->b;
  a -> aPrime
  aPrime->c:w;  
  aPrime->d:w;
  aPrime->e:w;
  c:e->bPrime;
  d:e->bPrime;
  e:e->bPrime
  bPrime->b
  }

Giving:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11