Causal Diagram (DAG) Maker from plain text

Free causal diagram maker. Type one arrow per line, get a clean DAG with exposure, outcome, confounder, mediator and collider styling. Download SVG or PNG.

Your DAG, one edge per line

Write A -> B, chains like A -> B -> C, roles like smoking [exposure], and quotes for names with spaces. Lines starting with # are comments.

5 variables, 7 arrows

Roles: exposure, outcome, confounder, mediator, collider, unobserved.

Causal diagram (directed acyclic graph)Causal diagram with 5 variables and 7 arrows: smoking to tar deposits; tar deposits to lung cancer; smoking to lung cancer; age to smoking; age to lung cancer; genotype to smoking; genotype to lung cancer.smokinglung cancertar depositsagegenotypeExposureOutcomeConfounderMediatorUnobservedArrow from an unobserved variable

Four classic causal diagrams

Each figure below is drawn live by the tool from the text behind it. Load one into the editor to change it. Sources: Hernan and Robins, Causal Inference: What If (chapters 6 to 8), and Greenland, Pearl and Robins (1999), Epidemiology 10(1):37-48.

Confounding

Causal diagram (directed acyclic graph)Causal diagram with 3 variables and 3 arrows: Confounder L to Exposure A; Confounder L to Outcome Y; Exposure A to Outcome Y.Confounder LExposure AOutcome YExposureOutcomeConfounder

A common cause L of exposure A and outcome Y opens the non-causal path A <- L -> Y; adjusting for L blocks it.

Mediation

Causal diagram (directed acyclic graph)Causal diagram with 3 variables and 3 arrows: Exposure A to Mediator M; Mediator M to Outcome Y; Exposure A to Outcome Y.Exposure AMediator MOutcome YExposureOutcomeMediator

M lies on the causal path from A to Y; adjusting for M blocks that indirect path, so the result is no longer the total effect of A.

Collider (M-bias)

Causal diagram (directed acyclic graph)Causal diagram with 5 variables and 5 arrows: U1 to Exposure A; U1 to Collider C; U2 to Collider C; U2 to Outcome Y; Exposure A to Outcome Y.U1U2Exposure ACollider COutcome YExposureOutcomeColliderUnobservedArrow from an unobserved variable

The path A <- U1 -> C <- U2 -> Y is blocked at the collider C; adjusting for C opens it and creates a non-causal association between A and Y.

Selection bias

Causal diagram (directed acyclic graph)Causal diagram with 3 variables and 2 arrows: Exposure A to Selected into study S; Outcome Y to Selected into study S.Exposure AOutcome YSelected into study SExposureOutcomeCollider

A and Y both affect selection S; analysing only the selected people (conditioning on S) can make A and Y associated even when neither causes the other.

Writing a thesis rather than drawing a causal model? The conceptual framework generator lays out variables and relationships without the causal assumptions of a DAG. For adjustment sets, use DAGitty.

What is a causal diagram?

A causal diagram is a drawing of your assumptions about what causes what. Each variable is a node and each arrow means "may have a direct causal effect on". In epidemiology and the social sciences the usual form is the causal directed acyclic graph, or DAG: arrows have one direction and there are no loops. Drawing the DAG before the analysis makes the assumptions visible to co-authors and reviewers, and it is the starting point for deciding which variables to adjust for. The standard references are Greenland, Pearl and Robins (1999), "Causal diagrams for epidemiologic research", Epidemiology 10(1):37-48, and Hernan and Robins, "Causal Inference: What If".

How to write a DAG in this tool

  • One edge per line: smoking -> cancer. Spaces around the arrow are optional.
  • Chains: A -> B -> C creates the edges A to B and B to C. You can also write A <- B when it reads more naturally, and mix both in one line.
  • Names with spaces go in double quotes: "birth weight" -> mortality.
  • Roles go in square brackets after a name, on an edge line or on a line of their own: smoking [exposure], cancer [outcome], age [confounder], tar [mediator], hospitalization [collider], U [unobserved]. A variable keeps one role.
  • Comments start with #. Blank lines are ignored.
  • If a line cannot be read, the message names the line number. If the arrows form a loop, the message shows the cycle, for example "Cycle: A -> B -> C -> A".

Node roles and how they are drawn

  • Exposure (blue rectangle): the variable whose effect you want to estimate.
  • Outcome (orange pill with a heavier outline): the variable you want to explain.
  • Confounder (yellow hexagon): a common cause of exposure and outcome, or of variables on paths to them.
  • Mediator (green parallelogram): a variable on the causal path from exposure to outcome.
  • Collider (pink diamond): a variable where two arrowheads meet on a path. Arrows meet at its points.
  • Unobserved (dashed ellipse): a variable you did not measure. Arrows that start at an unobserved variable are dashed too.
  • Color is never the only cue. Every role has its own shape, the legend names each one, and the grayscale option keeps the shapes. Colors follow the Okabe-Ito palette, which stays distinguishable for most color-vision differences.

The four classic structures

Almost every DAG is built from a few patterns. A confounder is a common cause, so it creates a non-causal association between exposure and outcome that adjustment removes. A mediator sits on the causal path, so adjusting for it removes the indirect part of the effect. A collider is a variable where two arrowheads meet on a path, so that path is closed until you condition on the collider or a descendant of it, and conditioning opens the path (M-bias is the best-known example). Selection bias is the same collider logic applied to who ends up in your study: if exposure and outcome both influence selection, analysing only the selected people can create an association. The examples above are drawn live by this tool, and Hernan and Robins explain each in detail in chapters 6 to 8 (graphs, confounding, selection bias) and chapter 23 (mediation).

When to use DAGitty instead

DAGitty (dagitty.net, checked October 2026) describes itself as a browser-based environment for creating, editing and analyzing causal diagrams, and it is free and open source. It computes minimal sufficient adjustment sets, testable implications and d-separation, and there is an R package. This page does none of that. It does not tell you what to adjust for. Use DAGitty when you need adjustment sets or implied conditional independencies. Use this page when you already have the structure and want a clean, consistent figure for a paper, thesis, slide or protocol, with shapes and colors for the roles and an export that opens in any editor.

What this tool does not do

It does not compute adjustment sets, check d-separation, test your DAG against data or tell you whether your assumptions are right. A DAG is only as good as the subject-matter knowledge behind it. The tool also draws a DAG, not a graph with feedback: if two variables affect each other over time, give each time point its own node. The same layout works for any acyclic graph, such as task dependencies, but it does not read pipeline code. Everything runs in your browser and the text you type is not uploaded.

Frequently Asked Questions