Code
library(ggdag)
library(tidyverse)
library(dagitty)
library(patchwork)
<- dagify(m ~ x, y ~ m + x,
med2 coords = list(x = c(x = 1, m = 1.5, y = 2), y = c(x = 1, y = 1, m = 1.5))
|>
) tidy_dagitty() |>
mutate(fill = ifelse(name == "m", "Mediator", "variables of interest")) |>
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_point(size = 7, aes(color = fill)) +
geom_dag_edges(show.legend = FALSE) +
geom_dag_text() +
theme_dag() +
theme(
legend.title = element_blank(),
legend.position = "top"
) med2