Open fBedecarrats opened 1 year ago
It is not easy. I managed to get 90% there, e.g.
at which point there was almost no code left from ggdag as I had to rewrite everything using dagitty
, ggforce
and ggraph
internals. And I did not find a way to get biasing paths 100% right (note how EDN1.9 → EDN1.10 is not coloured as biasing) as this is not exposed AFAIK as a public API of dagitty.
API-side it looks like this:
p = (
ggplot()
+ aes(x=x, y=y, xend=xend, yend=yend)
+ geom_dagitty_edge2()
+ geom_dagitty_node()
+ geom_node_label(nudge_y=-0.3)
+ theme_dagitty()
+ scale_y_continuous(expand = expansion(mult=0.25))
+ scale_x_continuous(expand = expansion(mult=0.25))
)
(
p %+% node_dagitty(dagitty::getExample('M-bias'))
+ p %+% node_dagitty(dagitty::getExample('mediator'))
+ p %+% node_dagitty(dagitty::getExample('Sebastiani'))
+ patchwork::plot_layout(design="AB\nCC", heights=c(1, 3), guides='collect')
+ patchwork::plot_annotation(tag_levels = 'a')
)
Thanks and bravo! Is there a snippet I could look at to understand how you approached this? (No hurry at all, I' m on holidays for the next 10 days)
Can you all tell me your goal in replicating the dagitty site output? Do you prefer the look? Are the legends and colors helpful to you in some capacity? I definitely don't intend on being able to do @krassowski did out of box with ggdag, but there may be core components here that would be useful to add
I uploaded my code here for reference https://github.com/krassowski/ggdagitty. Some places where I needed to extend ggdag
include:
adjusted
argument in dagify
(compare with here)ggdag::node_status
to
geom_dag_edges
to allow bi-directional relation to be shown without curvature, see hereSome related upstream issues are:
All three of those items would be good (preferably separate) PRs to ggdag
There's already an issue for the control point problem #21
Thanks again for this great package. One use-case I think for this package is to reproduce and enhance the DAG display proposed by daggity.net, that is node and edges with the following semiology:
I tried and found it not trivial to reproduce with {ggdag}. I think it might be useful to show how to reproduce such visualization in a vignette. Maybe it's just me, but I thought it might be of interest to other newcomers.