Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Last active May 21, 2019 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewheiss/640435ae89d7204dfe060a0a4eb62817 to your computer and use it in GitHub Desktop.
Save andrewheiss/640435ae89d7204dfe060a0a4eb62817 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggdag)
library(ggraph)

theory_dag <- dagify(AE ~ PF,
                     PF ~ IC + RC,
                     FIC ~ AE,
                     labels = c("AE" = "Advocacy\neffects", 
                                "PF" = "Programmatic\nflexibility",
                                "IC" = "Institutional\nconstraints",
                                "RC" = "Resource\nconfiguration",
                                "FIC" = "Future\ninstitutional\nconstraints"),
                     exposure = "PF",
                     outcome = "AE") %>% 
  tidy_dagitty(layout = "sugiyama")

theory_dag$data <- theory_dag$data %>% 
  mutate(linetype = ifelse(name == "AE", "dotted", "solid"))

plot_dag <- ggplot(theory_dag, aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_dag_point(size = 8) +
  geom_dag_edges(start_cap = circle(4, "mm"),
                 end_cap = circle(4, "mm"),
                 aes(edge_linetype = linetype)) +
  geom_dag_label_repel(aes(label = label), direction = "x", seed = 12345, size = 3) +
  scale_dag() +
  scale_edge_linetype_manual(values = c("dotted", "solid"), guide = FALSE) +
  theme_void()

plot_dag

Created on 2019-05-20 by the reprex package (v0.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment