ggdag
ggdag copied to clipboard
Improve coordinates api
I think the coordinates API is unclear, as several people (myself included) have stumbled over it or missed it altogether. I think this needs a few changes:
- [ ] Examples in the new customizing DAGs vignette
- [ ] A separate function that can specify coordinates, something like
dag_coords()
that will overridedagitty
object coords and, if it's already tidied, update thetidy_dag
coords.
However, I need to think about the second item more
FWIW, I think the API is very straightforward and natural. But it would be nice to have an example with a data.frame or tribble in the documentation. Personally, I tend to specify coordinates using something like this, since it makes the X-Y coordinates clearer:
library(ggdag)
coords <- read.table(header = TRUE, text = "
x y name
0 0 X
1 0 Z
2 0 Y
1 1 U
")
d <- dagify(
X ~ U,
Z ~ X,
Y ~ Z,
Y ~ U,
coords = coords)
ggdag(d)
I agree that this way is much clearer and should be more evident in the docs. I think any improvements will center around using the data frame approach
@vincentarelbundock this is a helpful suggestion. Thank you.