Description Usage Arguments Details Value Examples
View source: R/set_sem_layout.R
Configure the layout of factors and adjust other aspects of an SEM graph by semPlot::semPaths.
1 2 3 4 5 6 7 8 9 10 
semPaths_plot 
A qgraph::qgraph object generated by semPaths, or a similar qgraph object modified by other semptools functions. 
indicator_order 
A string vector of the indicators. The order of the names is the order of the indicators in the graph, when they are drawn on the bottom of the graph. The indicators should be grouped by the factors on which they load on. For example, if x1, x2, x4 load on f2, and x3, x5, x6 load on f1, then vector should be either c("x1", "x2", "x4", "x3", "x5", "x6") or c("x3", "x5", "x6", "x1", "x2", "x4"). Indicators within a group can be ordered in any way. 
indicator_factor 
A string vector of the same length of the
indicator order, storing the name of the factor for which each of
the indicator in 
factor_layout 
A matrix of arbitrary size. This matrix will serve as a grid for users to specify where each latent factor should be placed approximately on the graph. Each cell should contain NA or the name of a latent factor. The locations of all latent factors must be explicitly specified by this matrix. 
factor_point_to 
A matrix of the same size as 
indicator_push 
(Optional) This argument is used to adjust the
positions of the indicators of selected latent factors. It can be
named vector or a list of named lists. For a named vector, The name
is the factor of which the indicators will be "pushed", and the
value is how "hard" the push is: the multiplier to the distance
from the factor to the indicators. If this value is 1, then there
is no change. If this value is greater than 1, then the indicators
are pushed away from the latent factor. If this value is less than
1, then the indicators are pulled toward the latent factor. For
example, to push the indicators of 
indicator_spread 
(Optional) This argument is used to adjust
the distance between indicators of selected latent factors. It can
be a named vector or a list of named lists. For a named vector, the
name is the factor of which the indicators will be spread out. The
value is the multiplier to the distance between neighboring
indicators. If this value is equal to 1, there is no change. Larger
than one, the indicators will be "spread" away from each other.
Less than one, the indicators will be placed closer to each others.
For example, to spread the indicators of 
loading_position 
(Optional) Default is .5. This is used
adjust the position of the loadings. If this is one single number,
it will be used to set the positions of all loadings. If it is .5,
the loadings are placed on the center of the arrows. Larger the
number, closer the loadings to the indicators. Smaller the number,
closer to the latent factors. This argument also accepts a named
vector or a list of named lists, allowing users to specify the
positions of loadings for each factor separately. For a named
vector, in each element, the name is the factor whose loadings will
be moved. The value is the positions of its loadings. The default
is .50. We only need to specify the positions for factors to be
changed from .50 to other values. For example, move the loadings of

Modify a qgraph::qgraph object generated by semPaths based on an SEM model with latent factors. Currently only support a model in which all exogenous variables are latent factors, and all observed variables are indicators. If a variable has only one indicator, it is easier to
A qgraph::qgraph based on the original one, with various aspects of the model modified.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55  library(lavaan)
library(semPlot)
mod <
'f1 =~ x01 + x02 + x03
f2 =~ x04 + x05 + x06 + x07
f3 =~ x08 + x09 + x10
f4 =~ x11 + x12 + x13 + x14
f3 ~ f1 + f2
f4 ~ f1 + f3
'
fit_sem < lavaan::sem(mod, sem_example)
lavaan::parameterEstimates(fit_sem)[, c("lhs", "op", "rhs", "est", "pvalue")]
p < semPaths(fit_sem, whatLabels="est",
sizeMan = 5,
nCharNodes = 0, nCharEdges = 0,
edge.width = 0.8, node.width = 0.7,
edge.label.cex = 0.6,
style = "ram",
mar = c(10,10,10,10))
indicator_order < c("x04", "x05", "x06", "x07", "x01", "x02", "x03",
"x11", "x12", "x13", "x14", "x08", "x09", "x10")
indicator_factor < c( "f2", "f2", "f2", "f2", "f1", "f1", "f1",
"f4", "f4", "f4", "f4", "f3", "f3", "f3")
factor_layout < matrix(c("f1", NA, NA,
NA, "f3", "f4",
"f2", NA, NA), byrow = TRUE, 3, 3)
factor_point_to < matrix(c("left", NA, NA,
NA, "down", "down",
"left", NA, NA), byrow = TRUE, 3, 3)
indicator_push < c(f3 = 2, f4 = 1.5)
indicator_spread < c(f1 = 2, f2 = 2)
loading_position < c(f1 = .5, f2 = .8, f3 = .8)
# Pipe operator can be used if desired
p2 < set_sem_layout(p,
indicator_order = indicator_order,
indicator_factor = indicator_factor,
factor_layout = factor_layout,
factor_point_to = factor_point_to,
indicator_push = indicator_push,
indicator_spread = indicator_spread,
loading_position = loading_position)
p2 < set_curve(p2, c("f2 ~ f1" = 1,
"f4 ~ f1" = 1.5))
p2 < mark_sig(p2, fit_sem)
p2 < mark_se(p2, fit_sem, sep = "\n")
plot(p2)
#Lists of named list which are equivalent to the vectors above:
#indicator_push < list(list(node = "f3", push = 2),
# list(node = "f4", push = 1.5))
#indicator_spread < list(list(node = "f1", spread = 2),
# list(node = "f2", spread = 2))
#loading_position < list(list(node = "f1", position = .5),
# list(node = "f2", position = .8),
# list(node = "f3", position = .8))

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.