View source: R/med_mod_plots.R
plot_moderated_mediation | R Documentation |
This function helps to plot a moderated mediation model - with a single moderator and a single mediator. Labels for each path need to be specified manually. By default, covariates are only related to the outcome variable - if they are also used to estimate the mediator, the graph code needs to be adjusted manually.
plot_moderated_mediation(
X,
M,
W,
Y,
CV = NULL,
mod_direct_path = TRUE,
labels = list(a = "+", b = "+", c = "+", a_mod = "+", c_mod = "+"),
filename = NULL
)
X |
The name of the predictor variable |
M |
The name of the mediator variable |
W |
The name of the moderator variable |
Y |
The name of the outcome variable |
CV |
The name of covariates |
mod_direct_path |
Logical. Should a direct path from X to Y be included? |
labels |
A list of labels for the paths. See the example for the required names. |
filename |
The filename to save the plot to (should end in .svg). When NULL, the graph is not saved but simply returned. |
A named list with the code and the graph
plot <- plot_moderated_mediation(X = "Training", M = "Self-Efficacy",
W = "Motivation", Y = "Performance", CV = "Age, Gender",
mod_direct_path = TRUE, labels = list(a = "+", b = "+", c = "+",
a_mod = "+", c_mod = "+"),
filename = NULL)
# Show the graph
plot$graph
# Show the code
plot$code
# To create the graph again (e.g., after you edit its code)
DiagrammeR::grViz(plot$code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.