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

Fix guides #152

Merged
merged 6 commits into from
Mar 7, 2024
Merged

Fix guides #152

merged 6 commits into from
Mar 7, 2024

Conversation

malcolmbarrett
Copy link
Collaborator

Closes #146

@malcolmbarrett
Copy link
Collaborator Author

This change is causing an unusual bug in the status plots (or perhaps just detected by them). I thought maybe the new version of ggplot was unearthing a different bug but using the dev version of ggdag + the new ggplot works as expected

library(ggdag, warn.conflicts = FALSE)
test_dag <- dagify(
  y ~ x + w2 + w1,
  x ~ z1 + w1,
  z1 ~ w1 + v,
  z2 ~ w2 + v,
  w1 ~ ~w2,
  exposure = "x",
  outcome = "y"
)

test_dag <- tidy_dagitty(test_dag)

# right
ggdag_parents(test_dag, "x")

ggdag_children(test_dag, "v")

# wrong
ggdag_parents(test_dag, "y")

ggdag_children(test_dag, "x")

# right????
ggdag_parents(test_dag, "y", use_edges = FALSE) + geom_dag_edges()

ggdag_children(test_dag, "x", use_edges = FALSE) + geom_dag_edges()

Created on 2024-03-07 with reprex v2.1.0

@malcolmbarrett
Copy link
Collaborator Author

It's not yet clear to me why, but this regression appears to be due to removing drop = FALSE in scale_color_discrete(drop = FALSE). Adding it back in fixes the legend.

I still suspect that this may be unearthing a pre-existing bug on the ggdag side.

@malcolmbarrett
Copy link
Collaborator Author

I have a working theory on this. I think the edge geom is filtering values in some capacity that is dropping single values of either "child" or "node" but then breaks() is adding them back in, resulting in a poor legend as ggplot doesn't know the value added by breaks() is a missing level

It's not clear to me why not using an edge in geom_dag() then adding one manually changes that process. Perhaps having the geoms as a list() means they get processed all at once by ggplot, whereas doing an edge after means it doesn't impact how the data are filtered?

@malcolmbarrett malcolmbarrett marked this pull request as ready for review March 7, 2024 17:16
@malcolmbarrett
Copy link
Collaborator Author

This is fixed in tests but I do believe there is a more robust way to deal with this. I'll file another issue to explore later

@malcolmbarrett malcolmbarrett merged commit 795fe76 into main Mar 7, 2024
6 checks passed
@malcolmbarrett malcolmbarrett deleted the fix_guides branch March 7, 2024 21:00
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

Successfully merging this pull request may close these issues.

New version of ggplot2 causing guide breakages
1 participant