library(tidyverse)
library(rethinking)
library(dagitty)
library(ggdag)
draw_dag <- function(df) {
df |>
ggplot(aes(
x = x,
y = y,
xend = xend,
yend = yend,
color = status,
edge_linetype = linetype,
edge_color = linecolor
)) +
geom_dag_edges(
start_cap = ggraph::circle(20, 'mm'),
end_cap = ggraph::circle(20, 'mm'),
edge_width = 1,
arrow_directed = grid::arrow(
length = grid::unit(12, "pt"),
type = "open"
),
arrow_bidirected = grid::arrow(
length = grid::unit(24, "pt"),
type = "open",
ends = "both"
)
) +
geom_dag_node(size = 40) +
geom_dag_label(
aes(label = name),
fill = "white",
color = "black",
size = 4
) +
theme_dag_gray(legend.position = "none", aspect.ratio = .66) +
scale_x_continuous(expand = expansion(mult = 0.5)) +
scale_y_continuous(expand = expansion(mult = 0.5)) +
scale_color_manual(
values = c(
"exposure" = "#F8766D",
"outcome" = "#619CFF",
"latent" = "lightgray"
)
)
}