I want to draw the following diagram in R:
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.
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
There are vast options for customisation. See here as a starting point.