I produced a path diagram/directed acyclic graph (DAG) plot with dagitty and want to change the vertex labels to arbitrary strings, preferably that take in markdown or LaTeX formatting. I have been able to change them to any relatively short single value without spaces but not an arbitrary string and have not been able to implement the additional formatting. Is this possible?
The working example below provides code to demonstrate this:
- Figure 1 is the base figure.
- Figure 2 changes the labels and it works because it's short and has no spaces
- Figure 3 changes the labels to longer strong - fails!
- Figure 4 adds a space to the label - fails!
Ideally, I would be able to implement Figure 4 and, e.g. let vertex X_a or X_{a} produce X with subscript a.
library(dagitty)
library(ggdag)
# Figure 1 - BASE
g1 <- dagitty('dag {
X [pos="0,1"]
Y [pos="1,1"]
X -> Y
}')
plot(g1)
# Figure 2 - SUCCESSFUL LABEL CHANGE
g2 <- dagitty('dag {
Xsub [pos="0,1"]
Ysub[pos="1,1"]
Xsub -> Ysub
}')
plot(g2)
# Figure 3 - LABELS TOO LONG?, FAIL
g3 <- dagitty('dag {
XsubLONGSTRINGHERE [pos="0,1"]
YsubLONGSTRINGHERE[pos="1,1"]
XsubLONGSTRINGHERE -> YsuBLONGSTRINGHERE
}')
plot(g3)
# Figure 4 - SPACE FAIL
g4 <- dagitty('dag {
X sub [pos="0,1"]
Y sub[pos="1,1"]
X sub -> Y sub
}')
plot(g4)