Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DiagrammeR and graphviz

I am trying to reproduce the flow diagram from:

http://www.consort-statement.org/consort-statement/flow-diagram

using the DiagrammeR package from R. Below is where I got so far, but I can't get the "excluded" box to be horizontally aligned with the blank node. Any suggestions?

```{r, echo=FALSE, warning=FALSE, results='hide', message=FALSE}
 
library(pacman)
p_load(DiagrammeR)
 
grViz("digraph a_nice_graph { 
  node [fontname = Helvetica, shape = box, width = 4, fillcolor = LightSalmon, style = filled]
  assessed [label = 'Assessed for Elibibility (n = )']
  randomized [label = 'Randomized (n = )']
  allocatedA [label = 'Allocated to intervention A (n = )']
  allocatedB [label = 'Allocated to intervention B (n = )']
  lostA [label = 'Lost to follow-up (n = )']
  lostB [label = 'Lost to follow-up (n = )']
  analyzedA [label = 'Analyzed (n = )']
  analyzedB [label = 'Analyzed (n = )']
  blank[label = '', width = 0.01, height = 0.01]
  excluded[label = 'Excluded (n = )']

  subgraph cluster_0 {
    rankdir = TD
    color = white
    assessed -> blank [arrowhead = none]
    blank -> randomized
  }

  subgraph cluster_1 {
    rankdir = LR
    color = white
    blank -> excluded
  }
 
  randomized -> {allocatedA allocatedB}
  allocatedA -> lostA
  allocatedB -> lostB
  lostA -> analyzedA
  lostB -> analyzedB
}") 
```

Here is the resulting plot thus far:

enter image description here

like image 482
Ricardo Pietrobon Avatar asked Sep 02 '25 16:09

Ricardo Pietrobon


1 Answers

I'm not using RMarkdown but have checked with the browser, I believe this should work "as is" in your setup as well. The point is just putting blank and excluded into the same rank. No need for the subgraphs you have tried:

digraph a_nice_graph
{
    node [fontname = Helvetica, shape = box, width = 4, fillcolor = LightSalmon, style = filled]
    assessed [label = 'Assessed for Elibibility (n = )']
    randomized [label = 'Randomized (n = )']
    allocatedA [label = 'Allocated to intervention A (n = )']
    allocatedB [label = 'Allocated to intervention B (n = )']
    lostA [label = 'Lost to follow-up (n = )']
    lostB [label = 'Lost to follow-up (n = )']
    analyzedA [label = 'Analyzed (n = )']
    analyzedB [label = 'Analyzed (n = )']
    blank[label = '', width = 0.01, height = 0.01]
    excluded[label = 'Excluded (n = )']

    { rank = same; blank excluded }

    assessed -> blank[ dir = none ];
    blank -> excluded[ minlen = 3 ];
    blank -> randomized;
    randomized -> {allocatedA allocatedB};
    allocatedA -> lostA;
    allocatedB -> lostB;
    lostA -> analyzedA;
    lostB -> analyzedB;
}

yields

enter image description here

like image 188
vaettchen Avatar answered Sep 05 '25 09:09

vaettchen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!