alishinski / lavaanPlot

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

Node positions #17

Open jebyrnes opened 5 years ago

jebyrnes commented 5 years ago

If I try and set node_options to something like node_options = list(x = c(1,2,3,4)) to put my variables in a line, I get

Error: syntax error in line 3 near '('

Any fix for this so we can make customized plots with nodes where we want them?

Deleetdk commented 5 years ago

Bump @alishinski any update on this?

alishinski commented 5 years ago

Thanks for the prompt. @jebyrnes can you provide a reproducible example?

lordhagen94 commented 2 years ago

Has this been resolved? I also have troubles to position nodes and I can't find any information on what commands to use for repositioning. Any suggestions?

WillemSleegers commented 2 years ago

Same issue here; I hope it can still be resolved!

ClaudiuPapasteri commented 1 year ago

Yes, same issue. @alishinski here is a small reproducible example on how I managed what I wanted. For a small toy CFA I needed the two factors (F1 and F2) to be on the same level (equal y in the case of BT rankdir). This would have been easy if we could modify positioning of nodes, but I had to use rank=same to achieve desired output.

  library(lavaan)
  library(lavaanPlot)

  corel <- matrix(0.41, 4, 4)
  corel[1:2, 1:2] <- 0.64
  corel[3:4, 3:4] <- 0.64
  diag(corel) <- 1
  row.names(corel) <- colnames(corel) <- paste0("i", 1:4)
  corel

  lav_corel <- "
    F1 =~ i1 + i2
    F2 =~ i3 + i4
  "
  lav_corel_m <- lavaan::cfa(lav_corel, sample.cov = corel, estimator = "ML", std.lv = TRUE, sample.nobs = 1000)
  lav_corel_d <- lavaanPlot::lavaanPlot2(model = lav_corel_m, graph_options = list(rankdir = "BT"), include = "covs", coef_labels = TRUE) 
  lav_corel_d

1

  lav_corel_d$x$diagram <- paste0(    # edit diagram
    substr(lav_corel_d$x$diagram, 1, nchar(lav_corel_d$x$diagram)-1),
    "{rank=same;1;2;}",
    "}"
  )
  lav_corel_d

2

So, I guess the question is here, how we can edit node positions or at least edit some global graph settings linked to their position (like rank).