Created
April 2, 2018 16:15
-
-
Save malcolmbarrett/cba4ecb08eec6a9209cb5e68bc680e1f to your computer and use it in GitHub Desktop.
pDAG hack in ggdag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggdag) | |
library(ggraph) | |
library(dplyr) | |
dag <- confounder_triangle(x_y_associated = TRUE) %>% | |
tidy_dagitty() %>% | |
# add marker for undirected | |
mutate(undirected = ifelse(name == "x" & to == "y", TRUE, FALSE)) | |
# create a closure function to filter data | |
filter_undirected <- function(...) { | |
function(x) filter(x, ...) | |
} | |
dag %>% | |
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) + | |
geom_dag_point() + | |
geom_dag_text() + | |
geom_dag_edges_link(data = filter_undirected(!undirected)) + | |
# from ggraph | |
geom_edge_link(aes(start_cap = circle(9, "mm"), #shorten edges | |
end_cap = circle(9, "mm")), | |
data = filter_undirected(undirected)) + | |
theme_dag() + | |
scale_dag() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment