Search code examples
rggplot2diagram

Drawing simple mediation diagram in R


Is there a (preferably easy and straightforward) way to draw simple path diagrams with mediation coefficients in R?

I've been looking to DiagrammeR package but that looks like an overkill (and to be honest I failed to figure out how to make a plot).

Other options I know of are Dia or Inkscape but those require manual positioning, connecting paths etc.

mediation package has a plot option but that draws bootstrapped CIs and what I'd like to achieve is a simple path with coefficients like this one:

source: http://my.ilstu.edu/~jhkahn/medmod.html


Solution

  • While @baptiste solution might work as well, I was looking for a publishable format.

    Function plotmat from library(diagram) is the one that got me the closest to my example:

    path diagram

    For a reproducible example use:

    library(diagram)
    data <- c(0, "'.47*'", 0,
              0, 0, 0, 
              "'.36*'", "'.33* (.16)'", 0)
    M<- matrix (nrow=3, ncol=3, byrow = TRUE, data=data)
    plot<- plotmat (M, pos=c(1,2), 
                    name= c( "Math self-efficacy","Math ability", "Interest in the math major"), 
                    box.type = "rect", box.size = 0.12, box.prop=0.5,  curve=0)