Graphviz plot of Directed Acyclic Graph (DAG) for thrombolysis use in stroke#
An example DAG showing key determinants for outcome in stroke. This includes use of thrombolysis (a clot-busting treatment), and the patient characteristics that influence whether thrombolysis is used.
Set up graph#
from graphviz import Digraph
# Create a directed graph
g = Digraph()
# Set graph attributes
g.attr(overlap='scale')
g.attr(sep='0.25')
g.attr(layout='dot') # See https://graphviz.org/docs/layouts/
# Set node attributes
g.attr('node', shape='circle', fixedsize='true', width='1.4', height='1.4')
Define nodes#
g.node('outcome', label='Outcome', penwidth='2', color='red', fontname='times bold', fontcolor='Red')
g.node('stroke_team', label='Stroke\nteam', color='black', fontcolor='Black')
g.node('nihss', label='Stroke\nseverity', color='black', fontcolor='Black')
g.node('scan', label='Arrival to\nscan time', color='black', fontcolor='Black')
g.node('mrs', label='Prior\ndisability', color='black', fontcolor='Black')
g.node('age', label='Age', color='black', fontcolor='Black')
g.node('sleep', label='Onset during\nsleep', color='black', fontcolor='Black')
g.node('af', label='Atrial\nfibrillation', color='black', fontcolor='Black')
g.node('thrombolysis', label='Thrombolysis\n(use/time)', penwidth='2', color='red', fontname='times bold', fontcolor='Red')
g.node('anticoag', label='Anticoagulation', color='black', fontcolor='Black')
g.node('precise', label='Estimated or \nprecicely known\nonset time', color='black', fontcolor='Black')
Describe edges#
#g.edge('enquiries', 'central', color='DarkGoldenRod')
g.edge('nihss', 'outcome', color='Black') # style='dashed')
g.edge('stroke_team', 'outcome', color='Black')
g.edge('mrs', 'outcome', color='Black')
g.edge('age', 'outcome', color='Black')
g.edge('af', 'outcome', color='Black')
g.edge('thrombolysis', 'outcome', color='Red')
# Show confounders
g.edge('stroke_team', 'thrombolysis', color='Black')
g.edge('scan', 'thrombolysis', color='Black')
g.edge('nihss', 'thrombolysis', color='Black')
g.edge('mrs', 'thrombolysis', color='Black')
g.edge('age', 'thrombolysis', color='Black')
g.edge('af', 'anticoag', color='Black')
g.edge('anticoag', 'thrombolysis', color='Black')
g.edge('precise', 'thrombolysis', color='Black')
g.edge('sleep', 'thrombolysis', color='Black')
# Others
g.edge('stroke_team', 'scan', color='Black')
g.edge('sleep', 'precise', color='Black')
g.edge('age', 'mrs', color='Black')
g
#
# Save the graph as a PNG file
g.format = 'png'
g.render('thrombolysis_dag', cleanup=True)
'thrombolysis_dag.png'