Skip to contents

Set the attributes of labels of selected nodes.

Usage

set_node_label_size(semPaths_plot, values = NULL)

set_node_label_color(semPaths_plot, values = NULL)

Arguments

semPaths_plot

A qgraph::qgraph object generated by semPlot::semPaths, or a similar qgraph object modified by other semptools functions.

values

A named vector or a list of named list. See the Details section on how to set this argument.

Value

A qgraph::qgraph based on the original one, with the sizes of selected nodes changed.

Details

Modify a qgraph::qgraph object generated by semPlot::semPaths and change the label attributes of selected nodes.

Attributes Supported

The function set_node_label_size() set the attribute label.cex of the plot, corresponding to the argument label.cex of semPlot::semPaths(). It controls the size of the label of a node.

The function set_node_label_color() set the attribute label.color of the plot, corresponding to the argument label.color of semPlot::semPaths(). It controls the color of the label of a node.

These arguments can be set in three ways.

For a named vector, the name of an element should be the nodes for which the attributes are to be changed. The names need to the displayed names if plotted, which may be different from the names in the model.

For example, to change the label-related attribute of x, the name should be "x". Therefore, c("y" = 2, "x" = 3) changes the selected attributes of the nodes y and x to 2 and 3, respectively.

For a list of named lists, each named list should have two named values: node and new_value. The size-related attribute of node will changed based on new_value.

The second approach is no longer recommended, though kept for backward compatibility.

The last approach is setting the size-related attribute to a one-element vector with no name. All nodes in plot will then have their sizes changed based on this value.

Examples

mod_pa <-
  'x1 ~~ x2
   x3 ~  x1 + x2
   x4 ~  x1 + x3
  '
fit_pa <- lavaan::sem(mod_pa, pa_example)
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)


p_pa2v <- set_node_label_size(p_pa, c(x1 = 5, x2 = 10))
plot(p_pa2v)


p_pa2l <- set_node_label_color(p_pa, "red")
plot(p_pa2l)