Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R code to produce a Consort diagram programmatically using DiagrammeR?

Tags:

I would like to programmatically create a Consort diagram describing the flow of patients in a randomized trial.

Does anyone have R code to generate this diagram (see link below) using DiagrammeR?

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

like image 497
user25494 Avatar asked Nov 16 '16 21:11

user25494


1 Answers

Asked previously on stackoverflow 5 years ago. Answers use package diagram: creating tree diagram for showing case count using R

Google found some graphviz code: http://blogs.sas.com/content/graphicallyspeaking/2016/10/20/outside-box-consort-diagram/

RStudio can directly preview Graphviz .dot files:

https://blog.rstudio.org/2015/05/01/rstudio-v0-99-preview-graphviz-and-diagrammer/

Alternatively,

library(DiagrammeR)
consort <- file("consort.dot")
grViz(diagram = consort)
close(consort)

"consort.dot" follows:

digraph g {
start [shape = box, label = "CONSORT Graph"];
node0 [shape = box, label = "All Patients\nN=1000"];
node1 [shape = box, label = "Full Analysis Set\nN=800"];
node2 [shape = box, label = "Excluded\nN=100"];
node3 [shape = box, label = "Not Included\nN=100"];
node4 [shape = box, label = "Safety Set\nN=700"];
node5 [shape = box, label = "Not Dosed\nN=100"];
node6 [shape = box, label = "Treatment A\nN=200"];
node7 [shape = box, label = "Treatment B\nN=150"];
node8 [shape = box, label = "Treatment C\nN=200"];
node9 [shape = box, label = "Treatment D\nN=150"];
start -> node0 -> node1 -> node4 -> {node6 node7 node8 node9};
node0 -> node2;
node0 -> node3;
node1 -> node5;
}
like image 139
user25494 Avatar answered Sep 22 '22 16:09

user25494