Sam Weisenthal
Sam Weisenthal

Reputation: 2951

LateX names in Dagitty

Does anyone know of a way to make variable labels in Dagitty with LateX (eg, I wanted to include subscripts and greek: eg $\lambda_1$). I know that in plots for base R, there are ways to do this.

Here is a mininimal example

   library(dagitty)
    g = dagitty('dag{
  A [pos="-1,0.5"]
  W [pos="0.893,-0.422"]
  X [pos="0,-0.5"]
  Y [pos="1,0.5"]
  A -> Y
  X -> A
  X -> W
  X -> Y
}')
plot(g)

This gives a plot with A,B, etc as the labels.

Rather, I wanted something like $\alpha$ instead of A to be shown on the plot.

Upvotes: 0

Views: 361

Answers (1)

user2554330
user2554330

Reputation: 44808

Turns out this is kind of hard, because dagitty assumes the labels in the graph are plain text. The branch of it available using

remotes::install_github("https://github.com/dmurdoch/dagitty", "nodelabels", "r")

will let you rename nodes using "plotmath" notation (see ?plotmath in R). For example,

   library(dagitty)
    g = dagitty('dag{
  A [pos="-1,0.5"]
  W [pos="0.893,-0.422"]
  X [pos="0,-0.5"]
  Y [pos="1,0.5"]
  A -> Y
  X -> A
  X -> W
  X -> Y
}')
plot(g, nodenames = expression(X = lambda[1]))

renames the X node to something like $\lambda_1$:

screenshot

Upvotes: 1

Related Questions