'R DAG with curved arrow bypassing mediator

I am trying to create a directed acyclic graph (DAG) highlighting the role of a mediator. I am using the dagitty and ggdag packages. Example code:

coords <- list(
  x = c(y = 5, x =2, m = 4),
  y = c(y = 2, x =2, m = 2)
)

mydag_basic <- dagify(y ~ m + x ,
                      m ~ x,
                      outcome = "y",
                      coords = coords) 

ggdag_status(mydag_basic) + theme_dag() 

This creates the DAG as in the attached image. directed acyclic graph However, the direct arrow from x to y is not very visible, hidden by the mediator. I could change this by shifting the x upwards/downwards but I am wondering whether it is possible to simply have a curved arrow that goes from x->y instead.



Solution 1:[1]

I contacted the author of the ggdag package and he was kind to reply. See a solution here: https://github.com/malcolmbarrett/causal-inference-in-R/issues/32

library(ggdag)
library(ggplot2)
p <- dagify(
  y ~ l, 
  a ~ l, 
  coords = list(x = c(l = 1, a = 2, y = 3), y = c(l = 1, a = 1, y = 1))
) %>%
  ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_dag_point() +
  geom_dag_text() +
  theme_dag() +
  ylim(0, 2)

p + geom_dag_edges_arc(curvature = c(0, .5))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mariodrumblue