GitHub

Lifecycle: stable Project Status: Active - The project has reached a stable, usable state and is being actively developed. CRAN Version CRAN: Release Date CRAN RStudio mirror downloads Code size Last Commit at Master R-CMD-check

(Version 0.4.0, updated on 2026-07-20, release history)

Helper functions for modifying (postprocessing) plots generated by semPlot::semPaths() from the semPlot package.

Installation

The latest stable version can be installed from CRAN:

install.packages("semptools")

The latest development version at GitHub can be installed by remotes::install_github():

remotes::install_github("sfcheung/semptools")

To read the guides (vignettes) on how to use the functions, you can build the vignettes locally when installing the package:

remotes::install_github("sfcheung/semptools", build_vignettes = TRUE)

You can also find the guides under Articles of the Github page of this package.

Background

semPlot::semPaths() is a very useful function for visualizing structural equation models. We use it a lot. The output is a qgraph object which is highly customizable. Our area is in psychology and some users in this area may not know how to customize the graphs in aspects relevant to psychology. Therefore, we think it would be useful for users in psychology, including us, to have some functions for customizing the graphs from semPlot::semPaths(), without knowing the technical details of qgraph.

Philosophy

We though about the tasks we usually want to do with a semPlot::semPaths() graph, and wrote one function for each task. We wrote the functions such that all of them work by postprocessing a semPlot::semPaths() graph: receive a semPlot::semPaths() graph, modify it, and return a modified semPlot::semPaths() graph. This also allows users to use the the R pipe operator |> available since R 4.1.x (or the %>% operator from the magrittr package) to chain together modifications. For example:

modified_graph <- original_graph |>
                    task_1() |>
                    task_2(other_arguments) |>
                    task_3()

In psychology, two typical models are confirmatory factor analysis model and structural models with latent factors. Therefore, we also wrote two functions, set_cfa_layout() and set_sem_layout(), that can combine several common tasks together, such as specifying the positions of the latent factors and adjusting the positions of the indicators.

We also wrote the functions in a way that users do not need to know the technical detail (e.g., the position of the path in the list of all paths). For example, if a user wants to move the path coefficient of the path from x to y closer to y, the user only needs to tell the function that it is the path from x to y. The function will find which path it is in the qgraph object.

What we have so far

These are some functions included so far:

Add elements based on parameter estimates

  • mark_se(): Add the standard errors to parameter estimates.

  • mark_ci(): Add the confidence intervals to parameter estimates.

  • mark_sig(): Add asterisks ("*", "**", "***") based on

Read the original on github.com ↗