jtextor / dagitty

Graphical analysis of structural causal models / graphical causal models.
GNU General Public License v2.0
282 stars 46 forks source link

Allow nodes to be relabelled with plotmath expressions #45

Closed dmurdoch closed 2 years ago

dmurdoch commented 3 years ago

plot.dagitty assumes nodes are labelled with text, but R graphics supports using expressions for labels with the plotmath scheme. This adds a parameter to plot.dagitty called nodenames, that allows some or all of the nodes to be renamed. For example, this code

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 = alpha^2))

plots the graph with node X labeled using alpha^2.

jtextor commented 2 years ago

Thanks, and sorry for seeing this so late! I just made s slight change, the parameter is now called "node.names" so it's more consistent with the others.