Home > Back-end >  Text on top of the arrows in GGDAG
Text on top of the arrows in GGDAG

Time:07-28

I am trying to plot a ggdag plot (Directed Acyclic Graphs in R) using the wonderful ggdag package in R (enter image description here

Thanks!

CodePudding user response:

An option could be using annotate. Keep in mind that you need to use set.seed, because the dag will keep chaning from position randomly. You can use the following code:

library(ggdag)
library(ggplot2)
example <- ggdag::dagify(d ~ p,m ~ d,y ~ d,y ~ m)
set.seed(1)
ggdag::ggdag(example) theme_dag()  
  annotate("text", x = c(0.4, 0), , y = c(2.6, 2.3), , label = "beta==x p =xx")

Created on 2022-07-28 by the reprex package (v2.0.1)

  • Related