Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for a vignette enhancement #112

Open
fBedecarrats opened this issue May 29, 2023 · 5 comments
Open

Suggestion for a vignette enhancement #112

fBedecarrats opened this issue May 29, 2023 · 5 comments

Comments

@fBedecarrats
Copy link

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:
image
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.

@krassowski
Copy link

krassowski commented Aug 6, 2023

It is not easy. I managed to get 90% there, e.g.

image

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')
)

@fBedecarrats
Copy link
Author

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)

@malcolmbarrett
Copy link
Collaborator

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

@krassowski
Copy link

krassowski commented Aug 8, 2023

I uploaded my code here for reference https://github.com/krassowski/ggdagitty. Some places where I needed to extend ggdag include:

  • support for adjusted argument in dagify (compare with here)
  • wrapping ggdag::node_status to
    • add coordinates of control points to have nice curves as manually positioned in dagitty (see here)
    • add information about ancestry status for nodes, and path status for edges
  • geom_dag_edges to allow bi-directional relation to be shown without curvature, see here

Some related upstream issues are:

@malcolmbarrett
Copy link
Collaborator

All three of those items would be good (preferably separate) PRs to ggdag

There's already an issue for the control point problem #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants