R draw diagram with custom coefficients

110 Views Asked by At

I want to draw the following diagram in R:
enter image description here

I saw that the lavaan package has a function to build diagrams, however you need to provide an already fitted model. I just want to build the diagram above with my own coefficients and use it in Rmarkdown. Is there any straightforward way to achieve this? Colors are not important.

1

There are 1 best solutions below

5
On BEST ANSWER

Here is one solution:

library(DiagrammeR)

grViz("
digraph {
node [shape=none] IV1; IV2; MED; DV

IV1 -> MED [label=3.2] 
IV1 -> DV [label=0.2] 
IV2 -> DV [label=9.3]
IV2 -> MED [label=0.5]
MED -> DV [label=5.1]
}"
)

Giving

enter image description here

There are vast options for customisation. See here as a starting point.