Drawing simple mediation diagram in R
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:
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)
R draw diagram with custom coefficients
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.
Print DiagrammeR object inside for-loop
Here is how to fix it:
# Create an empty list to save the htmlwidgets
plot_list <- htmltools::tagList()
for (i in 1:2){
graph <- DiagrammeR::grViz("
digraph test {
node [shape = circle]
A; B
A -> B
}
")
# Store the htmlwidget inside this list
plot_list[[i]] <- graph
}
#Print this list
plot_list
Related Topics
How to Make an Overlapping Barplot
How to Preprocess Features When Some of Them Are Factors
How to Speed Up R Packages Installation in Docker
Multiple Filled.Contour Plots in One Graph Using with Par(Mfrow=C())
Are Dataframe[ ,-1] and Dataframe[-1] the Same
Extract Time Series of a Point ( Lon, Lat) from Netcdf in R
Convert String Date to R Date Fast for All Dates
R/Quantmod: Multiple Charts All Using the Same Y-Axis
Conditionally Apply Pipeline Step Depending on External Value
Combined Line & Bar Geoms: How to Generate Proper Legend
Ggplot2 Find Number of Counts in Histogram Maximum
Frequency Table with Several Variables in R
Can Ggplot Make 2D Summaries of Data
Unquote the Variable Name on the Right Side of Mutate Function in Dplyr
Include Zero Frequencies in Frequency Table for Likert Data
How to Loop Through a Folder of CSV Files in R
Different Results with Randomforest() and Caret's Randomforest (Method = "Rf")