Set the line types of selected edges.
Arguments
- semPaths_plot
A qgraph::qgraph object generated by semPlot::semPaths, or a similar qgraph object modified by other semptools functions. It can also be a list of qgraph::qgraph objects, probably though not necessarily from a multigroup model. If it is a list of qgraph::qgraph objects, then the function will be applied to all the objects.
- line_type_list
A named vector or a list of named list. See the Details section on how to set this argument.
- check_direction
If
FALSE, the direction of an edge is ignored. For example, bothy ~ xandx ~ ywill affecty ~ x,x ~ y, andy ~~ x. Useful when we want to change an edge regardless of its direction and whether it is directional.
Value
A qgraph::qgraph based on
the original one, with widths for
selected edges changed.
If semPaths_plot is a list of
qgraph::qgraph objects, then a
list of processed qgraph::qgraph objects
will be returned.
Details
Modified a qgraph::qgraph object generated by semPlot::semPaths and change the widths of selected edges.
Setting the value of line_type_list
This argument can be set in three ways.
For a named vector, the name of an
element should be the path as
specified by lavaan::model.syntax
or as appeared in
lavaan::parameterEstimates().
For example, to change the line type of the
path regressing y on x, the name
should be "y ~ x". To change the
line type of the covariance between x1
and x2, the name should be "x1 ~~ x2". Therefore, c("y ~ x1" = "dotted", "x1 ~~ x2" = "dashed") changes the
line types of the path from x1 to y
and the covariance between x1 and
x2 to "dotted" and "dashed",
respectively.
The order of the two nodes may matter for covariances. Therefore, if the attribute of a covariance is not changed, try switching the order of the two nodes.
For a list of named lists, each named
list should have three named values:
from, to, and new_line_type. The
attribute of the edge from from to
to will be set to new_line_type.
The second approach is no longer recommended, though kept for backward compatibility.
The third approach is one single unnamed value. This value will be applied to all edges.
Supported Line Type
The supported line types are the
same line types supported by
the lty argument of par():
"blank" (0), "solid" (1),
"dashed" (2), "dotted" (3),
"dotdash" (4), "longdash" (5),
and "twodash" (6). The new line
type can be specified in either
strings or integers, but not both.
Examples
mod_pa <-
'x1 ~~ x2
x3 ~ x1 + x2
x4 ~ x1 + x3
'
fit_pa <- lavaan::sem(mod_pa, pa_example)
lavaan::parameterEstimates(fit_pa)[, c("lhs", "op", "rhs", "est", "pvalue")]
#> lhs op rhs est pvalue
#> 1 x1 ~~ x2 0.005 0.957
#> 2 x3 ~ x1 0.537 0.000
#> 3 x3 ~ x2 0.376 0.000
#> 4 x4 ~ x1 0.111 0.382
#> 5 x4 ~ x3 0.629 0.000
#> 6 x3 ~~ x3 0.874 0.000
#> 7 x4 ~~ x4 1.194 0.000
#> 8 x1 ~~ x1 0.933 0.000
#> 9 x2 ~~ x2 1.017 0.000
m <- matrix(c("x1", NA, NA,
NA, "x3", "x4",
"x2", NA, NA), byrow = TRUE, 3, 3)
p_pa <- semPlot::semPaths(fit_pa, whatLabels="est",
style = "ram",
nCharNodes = 0, nCharEdges = 0,
layout = m)
my_line_type_vector <- c(
"x2 ~~ x1" = "dotted",
"x4 ~ x1" = "dashed"
)
p_pa2v <- set_edge_line_type(
p_pa,
my_line_type_vector)
plot(p_pa2v)
my_line_type_list <- list(
list(
from = "x1",
to = "x2",
new_line_type = "dotted"),
list(
from = "x1",
to = "x4",
new_line_type = "dashed")
)
p_pa2l <- set_edge_line_type(
p_pa,
my_line_type_list
)
plot(p_pa2l)
