alishinski / lavaanPlot

R package for plotting lavaan path models with DiagrammeR
http://alexlishinski.com/lavaanPlot/
38 stars 4 forks source link

node_options color #26

Closed gsborgeest closed 3 years ago

gsborgeest commented 3 years ago

Hi Alex, I am trying to colour code my observed variables.

I can give them all the same colour (for example red) like this:

node_options = list(shape = "box", fontname = "Constantia", color = "red")

but I am not managing to assign different colours to different variables. I tried to create a list similar to what you do for labels like this:

colourz <- list(var1 = "green", var2 = "red", var3 = "grey") But running:

lavaanPlot(model = fitWBregions, 
           labels = labels, color = colourz,
           node_options = list(shape = "box", fontname = "Constantia" ), 
           edge_options = list(color = "grey"), 
           coefs = TRUE, stand = TRUE, stars = c("regress"), covs = TRUE)

gives this error:

Error in buildPaths(model, ...) : unused argument (color = colourz)

While running it like that:

lavaanPlot(model = fitWBregions, 
           labels = labels,
           node_options = list(shape = "box", fontname = "Constantia", color = colourz), 
           edge_options = list(color = "grey"), 
           coefs = TRUE, stand = TRUE, stars = c("regress"), covs = TRUE)

Results in an error in the plot (rather than the console):

Error: syntax error in line 3 near '('

I think the same error was previously mentioned in another post on your github, too, but didn't get resolved.

Do you know if it is possible to assign different colours?

alishinski commented 3 years ago

To do different formatting for different nodes in GraphViz, you need to use subgraphs, which I don't have implemented in lavaanPlot right now. But it's near the top of the list of things I want to implement.