change_node_label: Change node labels

View source: R/change_node_label.R

change_node_labelR Documentation

Change node labels

Description

Change the labels of selected nodes.

Usage

change_node_label(
  semPaths_plot,
  label_list = NULL,
  label.cex,
  label.scale,
  label.prop,
  label.norm
)

Arguments

semPaths_plot

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

label_list

A list of named lists. Each named list should have two named values: node and to. The first part, node, is a character denoting the label to be changed. It should be as appeared in the qgraph. The second part, to, is the new label. Expression can be used in to. A named vector can also be used, with the names being the nodes to be changed, and the values the new labels.

label.cex

Identical to the same argument in semPlot::semPaths(). A number tha control the size of labels in the nodes. It has no default. If not set, then this option in the semPaths_plot will not be changed.

label.scale

Identical to the same argument in semPlot::semPaths. A logical value that determine whether labels wil be scaled (resized) to the nodes they attach to. It has no default. If not set, then this option in the semPaths_plot will not be changed.

label.prop

Identical to the same argument in semPlot::semPaths. A numeric vector of length equal to the number of nodes. If label.scale is TRUE, this number is the proportion of the width of a node that its label will be scaled (resized) to. It has no default. If not set, then this option in the semPaths_plot will not be changed.

label.norm

Identical to the same argument in semPlot::semPaths. It must be a string. All labels as wide as or narrower than this string will have the same font size, while all labels wider than this string will be rescaled to have the same width as this string. It has no default. If not set, then this option in the semPaths_plot will not be changed.

Details

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

Value

A qgraph::qgraph based on the original one, with node attributes of selected nodes modified.

Examples

library(semPlot)
library(lavaan)
mod_pa <-
 'x1 ~~ x2
  x3 ~  x1 + x2
  x4 ~  x1 + x3
 '
fit_pa <- sem(mod_pa, pa_example)
parameterEstimates(fit_pa)[, c("lhs", "op", "rhs", "est", "pvalue")]
m <- matrix(c("x1",   NA,   NA,
               NA, "x3", "x4",
             "x2",   NA,   NA), byrow = TRUE, 3, 3)
p_pa <- semPaths(fit_pa, whatLabels="est",
           style = "ram",
           nCharNodes = 0, nCharEdges = 0,
           layout = m)

my_label_list <- list(list(node = "x3", to = "mediator"),
                     list(node = "x4", to = expression(gamma)))

p_pa2 <- change_node_label(p_pa, my_label_list)
plot(p_pa2)


semptools documentation built on Oct. 15, 2023, 5:07 p.m.