0

I'm using ggdag to create a DAG such as

test <- dagify("a" ~ "b",
    "b" ~ "c",
    "c" ~ "d",
    "b" ~ "d",
    exposure = "b",
    outcome = "d",
    labels = c(a = "A",
        b = "B",
        c = "D"))

And with ggplot I can get nice control of the colors such as

test %>%
    ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
        geom_dag_point(color = "orange") +
        geom_dag_edges_arc(edge_color = "blue", curvature = 0) +
        geom_dag_text(color = "black") +
        theme_dag()

pretty dag

But I can't get it to display labels, such as in

ggdag(test, text = FALSE,
    use_labels = "label", edge_type = "link_arc")

dag with labels

How do I get labels with DAGs and ggplot?

pgcudahy
  • 1,542
  • 13
  • 36
  • I'm not sure what you are looking for here. There _are_ labels in your final plot (the white boxes with the letters in them). What is it that you are expecting? – Allan Cameron Jul 10 '23 at 12:52
  • I'd like those labels to be in a ggplot figure, without having to use the `ggdag` convenience function, since it seems more stylistically limited than using the `ggplot` function with geoms – pgcudahy Jul 10 '23 at 12:53

1 Answers1

1

I figured out that the documentation refers to geom_dag_repel_label but the function is really geom_dag_label_repel

test %>%
    ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
        geom_dag_point(color = "orange") +
        geom_dag_edges_arc(edge_color = "blue", curvature = 0) +
        geom_dag_label_repel(aes(label = label), colour = "black", show.legend = FALSE) +
        theme_dag()

enter image description here

pgcudahy
  • 1,542
  • 13
  • 36